highlights every other row

pedy

Board Regular
Joined
Jan 6, 2006
Messages
217
Hi,

I have this bit of code that highlights every other row. I would like to modify it so that it doesn't highlight the entire rows but instead stops at the column of whichever cell contains data.

For instance if I’m using a block of cells such as A1 to C5 it would highlight A2-B2-C2 & A4-B4-C4 only. Later on if I insert data in D3 it would now highlight A2-B2-C2-D2 & A4-B4-C4-D4. Anytime that data would be inserted into a new column all row highlight would now adapt to the new length of the table.

Here’s the code:

Sub ShadeEverySecondRow()
Dim lRow As Long
lRow = 0
Do
lRow = lRow + 2
If IsEmpty(Cells(lRow, 1)) Then Exit Do
Rows(lRow).Interior.ColorIndex = 15
Loop
End Sub


Any help is appreciated

Pedy
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi, Pedy,

I'm really unregular poster these times. Very few time left: if you show an example + required result, then it will be easier to find out quickly what you need.

best regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

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