Range of cells for loop

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
984
Office Version
  1. 2021
Platform
  1. Windows
Hello, I have:
VBA Code:
Sub ShowIce()
Dim i As Integer
Sheets("EAP L1 - Current Mainline").Activate
For i = 6 To 600
If Cells(Range("23:28"), i).Interior.ColorIndex = 44 Then
Columns(i).EntireColumn.Hidden = False
End If
If Cells("23:28", i).Interior.ColorIndex = 46 Then
Columns(i).EntireColumn.Hidden = True
End If
Next i

Instead of keying on row 23 for my loop, I am trying to have a range of cells from row 23 to row 28 with the color index of 44
Same for the second IF only for color index of 46

How can I do this? If I only have one row, say row 23...the code works fine.

Thank you
 
There are some syntax problems. Also I suggest indenting your code to show structure. What do you want to do if, in the same column, one row has a color of 44 and another is a color of 46? The current result will be whichever one it checks last.
VBA Code:
Sub ShowIce()

   Dim i As Integer
   Dim R As Integer
  
   Sheets("EAP L1 - Current Mainline").Activate
  
   For i = 6 To 600
      For R = 23 To 28
     
         If Cells(R, i).Interior.ColorIndex = 44 Then
            Columns(i).EntireColumn.Hidden = False
         ElseIf Cells(R, i).Interior.ColorIndex = 46 Then
            Columns(i).EntireColumn.Hidden = True
         End If
     
      Next R
   Next i

End Sub
 
Upvote 0
Thank you...I will try this and report back
 
Upvote 0

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