Graying Out Some Rows

  • Thread starter Thread starter Tamer Seoud
  • Start date Start date
T

Tamer Seoud

Hi,
I never did Excel programming before, but I do VB
programming. I have a spreadsheet with many rows and
columns, to make it more easy to read the data in each
row, I was wondering if there is a way to program the
spreadsheet the way that every other row is grayed out.
Please help and please tell me how to access Excel modules
to type in the code.
Thanks a million.
Tamer
 
Tamer,

Do the following:

1) Press ALT+F11 to open the VBA Editor.
2) There, go to the Insert menu and choose module.
3) In the Module, paste the following code

Sub ColorRows()
Dim RowNdx As Long
For RowNdx = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
_
Step 2
Rows(RowNdx).Interior.ColorIndex = 15
Next RowNdx
End Sub

4) Flip back to Excel
5) Pres ALT+F8 to display the Macro dialog
6) Choose ColorRows and click Run.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
You can do this with conditional formatting
format>conditional formattting>cond 1>select formula is>type in
=mod(row(),2)=0 and format as desired>copy to other cells or select cells
first
 
Chip,
Thanks for your reply. I tried what you told me but I get
an error message "Syntax Error". Am I supposed to paste
the exact code you sent me or I have to change something
on it? And What is the "_" in the code between the first
part and Step 2? It seems there is a problem with the "_".
Please advise. Thanks again for your help.

Tamer
 
Tamer,

The lines got split in the posted message.

Try

For RowNdx = 1 To ActiveSheet.UsedRange.SpecialCells _
(xlCellTypeLastCell).Row Step 2

The " _" character is a line continuation character that lets you write one
logical line of code on two actual lines of text.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top