Color Non-Adjacent Columns from Header to Last Active Cell

cr2289

New Member
Joined
Jul 21, 2016
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hello All. I have a spreadsheet where I need to color non-adjacent columns from the column header down to the last active cell. I'm using the VBA below but it's only coloring the header. There are multiple ranges but I'll just show the first two. There are no values in the columns and I just need the shading. This has worked for years and now it doesn't. What am I doing wrong? Please help.

Dim IR As Long
IR = Cells(Rows.Count, "A").End(xlUp).Row
Range("G1:G" & IR).Interior.ColorIndex = 20
Range("I1:I" & IR).Interior.ColorIndex = 20
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Are there values in col A beyond the header? If not then lR = 1 and your ranges are confined to the 1st cell in the column.
 
Upvote 0
I think this macro will work for you...
VBA Code:
Sub cr2289()
  Dim IR As Long
  IR = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  Intersect(Range("G:G,I:I"), Range("1:" & IR)).Interior.ColorIndex = 20
End Sub
 
Upvote 0
I think this macro will work for you...
VBA Code:
Sub cr2289()
  Dim IR As Long
  IR = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  Intersect(Range("G:G,I:I"), Range("1:" & IR)).Interior.ColorIndex = 20
End Sub
Thank you so much! Worked wonderfully!
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,398
Members
449,222
Latest member
taner zz

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