VBA to conditionally change background color...

WiccaChic

New Member
Joined
Feb 10, 2004
Messages
5
This is going to seem like a dumb and pointless issue, but its a user request from a very impotrant user, so I hope you understand.

I have a an Excel97 worksheet that has about 500,000 cells that have a black background (others have other various color backgrounds) and I want to change just the cells with black backgrounds to have a red background. I figured there must be a simple way to do this using VBA or VBS...but I will admit I am a total total VBA tard!
:coffee:
Please help!
 

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.
Hmm....maybe something like this...

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> ChangeColors()
    <SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range
    
    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
    
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Selection
        <SPAN style="color:#00007F">If</SPAN> c.Interior.Color = vbBlack <SPAN style="color:#00007F">Then</SPAN> c.Interior.Color = vbRed
    <SPAN style="color:#00007F">Next</SPAN>

    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Hi,

how about this code:
Code:
Sub xxx()
Dim R As Range

For Each R In Sheets("Sheet1").UsedRange
    
    If R.Interior.ColorIndex = 1 Then
        R.Interior.ColorIndex = 3
    End If
Next R

End Sub

To implement:
1) [Alt-F11]
2) Insert|Module
3) Paste above code into the module window.

HTH

Alan
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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