VBA cell color

npacker

Board Regular
Joined
Oct 14, 2004
Messages
132
Can I call and change cell colors in VBA? I would like some code in the "ThisWorkbook" sub to say something like
Code:
If Range("C7").color = "red" Then
Range("D7").color = "red"
or something to that effect. Any help?
Thanks,
Nate
 
npacker,

1. Press Alt-F11
2. Select view from the menu, and make sure the vba project manager is visible.
3. Right click on the worksheet name in the project explorer.
4. Select Insert...Module
5. Double click on the module
6. Add the code to the module.
7. From Excel select Tools...Macro....Macros and selct the getcolor Macro.

HTH
Cal

Heya Smitty.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Put the code in a general module and call it from a blank worksheet.

It will list the Color # and color in A1:B56. You can then reference the list.

See http://www.cpearson.com/excel/colors.htm for more detailed info on working with colors, especially those generated with Conditional Formatting.

Smitty

What's up Matt :-P
 
Upvote 0
Oh I see, you were just giving me the color list. Thanks! Now my only problem is this. Once I figure out the colors I want, and I put in this code:
Code:
Private Sub ColorChange()
If Range("C7").Interior.Color = vbRed Or Range("C21").Interior.Color = vbRed Or Range("C35").Interior.Color = vbRed Then
Range("A6").Interior.Color = vbRed
End If
I've got the code in the "ThisWorkbook" property, and not in it's own module. It doesn't do anything currently, cause it's not being called by anything. How do I get it to be called continuously so when any of those cells change color, it automatically updates?
Nate
 
Upvote 0
I'm just bumping this up to the top, cause I really am curious! Oh, and I noticed on my previous code I forgot to put "End Sub" Don't worry, that's not my prolem, it's in the code.
Thanks,
Nate
 
Upvote 0

Forum statistics

Threads
1,224,804
Messages
6,181,056
Members
453,015
Latest member
ZochSteveo

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