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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

TommyGun

MrExcel MVP
Joined
Dec 9, 2002
Messages
4,202
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>
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,091
Messages
5,857,310
Members
431,870
Latest member
Muratculous

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
Top