Button to replace several colors by others within a range of cells

schinois

New Member
Joined
Oct 18, 2008
Messages
6
Hello,

I'm pretty new to programming in general :) So your assistance would be very well appreciated ;)

Where it applies?
To the sheet named "Localization" within the range Range("A15:AF2035").

When it applies?
By clicking on a command button (control)

What is the goal?
To replace all cells containing:
Color 1 (Interior.ColorIndex = 35)
AND/OR
color 2 (Interior.ColorIndex = 24)
BY
color 3 (Interior.ColorIndex = 2)


How would you write the code in VBA?

Thanks a lot in advance if you can help me,

Stephane
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Stephane,

Welcome to the Board.

Something like the below perhaps ?

Code:
Private Sub CommandButton1_Click()
Dim rng As Range: Set rng = Range("A15:AF2035")
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In rng
    Select Case cell.Interior.ColorIndex
        Case 35, 24
            new_col_ind = 3
        Case Else
            new_col_ind = 0
    End Select
    If new_col_ind > 0 Then cell.Interior.ColorIndex = new_col_ind
Next cell
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks lasw10!

Clean, working, and quickly done! Everythings is working the way I wanted to.

Thanks again!

Stephane
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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