EASY - Formatting Odd Numbered Rows

jrnyman

Board Regular
Joined
Mar 10, 2002
Messages
105
I'm looking for the code to shade the interior of each odd numbered row to colorindex=15. Right now I go line by line with a manual counter that changes from 0 to 1 or 1 to 0 at the end of each run of the loop. There's got to be a more efficient way to do this. Any suggestions?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
(1) Click on Format > Conditional Formatting.
(2) In the first drop down box, select "Formula Is"
(3) In the field at the right of that, enter
=MOD(ROW(),2)=1
(4) Click the Format button, then Patterns tab.
(5) Color index 15 is light gray, so choose that and hit OK, OK.
 
Upvote 0
Sub colorevenrows()

Do While Not IsEmpty(ActiveCell)
If ActiveCell.Row Mod 2 = 0 Then
' for odd
' if activecell.row mod 2<> 0 then
ActiveCell.EntireRow.Interior.ColorIndex = 15
End If
ActiveCell.Offset(1, 0).Select
Loop

End Sub

ni****h desai
http://www.pexcel.com
This message was edited by nisht on 2002-04-18 03:33
 
Upvote 0
jrnyman --

Thinking about your question and my response, you asked for code but I gave you a non-code answer because you also asked for efficiency. Loops tend to be inefficient, but so might a large range that is conditionally formatted. There're pros and cons with either approach; it depends on your preference and spreadsheet design.
 
Upvote 0
Thanks everyone for the help.

For anyone who thinks VBA is just like English chew on this:

Do While Not IsEmpty(ActiveCell)

translates to ENGLISH as..

Do (below) while active cell is not empty

Must have been too easy to do it that way....
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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