VBA code to change fill color of a cell if it contains any string

wrecclesham

Board Regular
Joined
Jul 24, 2019
Messages
52
Office Version
  1. 365
Platform
  1. Windows
I want to conditionally format cells in the range A1:A200 that contain any string.

If a cell is blank, no formatting should apply to that cell, but once any string is entered in a given cell, that individual cell should have its fill changed.

Any ideas?
 
I tried deleting my existing VBA code and replacing it entirely, just for testing purposes.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I pasted it here, where my previous VBA code was:

I'm quite new to this, so I'm probably missing something basic.

<a href="https://imgur.com/xkn1UHY"><img src="https://i.imgur.com/xkn1UHY.png" title="source: imgur.com" /></a>
 
Upvote 0
Other than pasting it into the code editor, I'm not actually running it. The other piece of VBA code I'm using (for automatic alphabetizing) ran automatically.

I assumed this would be the same but perhaps I'm wrong?
 
Upvote 0
Put your original code back in & just add the code you've shown at the end, just before the End Sub line
 
Upvote 0
You're a genius!! :)

Those five lines of code do exactly what I want. You even matched the colors from my screenshot!

Now I can drag and drop or copy and paste hard values between the two columns without worrying about rules being affected in the process.

This is the elegant solution that I had in mind from the start. I wasn't expecting to have a perfect working solution less than 24 hours after posting my question, that's for sure!

THANK YOU!!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top