VBA: If Any Cell in a Range is Yellow Then Do Not Change Color.

mykulpasskwa

Board Regular
Joined
Mar 20, 2018
Messages
66
Hi, I have different ranges of cells where once a cell goes over a limit then that cell changes yellow. Once one cell changes yellow in the range I don't want the cells after to change yellow. The ColorIndex of every other cell is 24 if that's helpful. For example, in a range of F4:F7 if the limit is reached in F5 then that should change yellow (6) but F6 and F7 should stay blue (24). This is what I have so far:

VBA Code:
                    For Each oneCell In Range("F" & f & ":F" & X)
                        If oneCell.Interior.ColorIndex = 6 Then 'Do Nothing
                            Else: If counter >= giresult Then ws.Range("F" & X).Interior.ColorIndex = 6
                        End If
                    Next
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
VBA Code:
If oneCell.Interior.ColorIndex = 6 Then 
    'Do Nothing
Else
    If counter >= giresult Then 
        ws.Range("F" & X).Interior.ColorIndex = 6
        Exit For
    End If
End If
 
Upvote 0
I wasn't able to get that to work properly, but after fiddling around with it for a while I came up with this and it seems to do the trick.

Edit: Sorry, let me rephrase, I wasn't able to get that exact code to work but after adding the
VBA Code:
Range("F" & f & ":F" & X).Select
your code worked perfectly! Thank you!

VBA Code:
        For Each oneCell In Range("F" & f & ":F" & X).Cells(f, 0)
            If oneCell.Interior.ColorIndex = 6 Then
                    'Do Nothing
                Else
                    If counter >= giresult Then
                        Range("F" & f & ":F" & X).Select
                        ws.Range("F" & X).Interior.ColorIndex = 6
                        Exit For
                    End If
                End If
            Next
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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