Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50090

Going Through Range and Performing If Statement

$
0
0
I'm just trying to loop through all the worksheets in the workbook and if a particular fill color is present in a cell change the cell fill color to another color. I'm not receiving any errors but when I step through the code, it does not seem to be going through each cell in the range. If anybody can point out where I'm going wrong it would be much appreciated.

Code:

Sub ChangeColors()


    Dim rngCell As Range
  Dim ws As Worksheet
 
    For Each ws In ActiveWorkbook.Worksheets
  ' ActiveSheet.Cells(1, 1).Activate
'ActiveCell.SpecialCells(xlLastCell).Select
lastRow = ActiveCell.Row
lastCol = ActiveCell.Column

Set MR = Range("a1", ActiveSheet.Cells(lastRow, lastCol))
For Each rngCell In MR
   
        If rngCell.Interior.ColorIndex = 39 Then
            rngCell.Interior.ColorIndex = 15
        End If
    Next rngCell
   
Next ws

End Sub


Viewing all articles
Browse latest Browse all 50090

Trending Articles