Hi need help with RowSelection

M

M&M

Im sure this is an elementary question but I'd rather ask than to spend two
hours trying to figure it out.

I have the macro below:

Sub ShadingMacro()
Dim i As Integer
i = 2
Do Until IsEmpty(Cells(i, 1))
Cells(i, 1).EntireRow.Interior.ColorIndex = 15
i = i + 2
Loop
End Sub


How do I click that same command button again to undo the highlighted rows??
 
B

BigPig

Hi M& M

You could try using a toggle button instead of a cmd btn and use the same
procedure that you wrote, and then set the colorindex to 0 to change it back
to 'unhighlighted'. Or put in another cmd btn and use your code but change
the colorindex to 0.

hth

BigPig
 
B

Bob Phillips

Sub ShadingMacro()
Static fSet As Boolean
Dim iLastRow As Long
With ActiveSheet
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With Rows("1:" & iLastRow)
If fSet Then
.Interior.ColorIndex = 0
Else
.Interior.ColorIndex = 15
End If
End With
fSet = Not fSet
End With
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

Bob Phillips

That 0 should be xlColorindexNone

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Top