Macro for fill color alternative rows

Closed
jk - Aug 28, 2009 at 09:09 AM
 nick316igr - Apr 18, 2013 at 09:27 PM
Hello,

I want a macro for fill color alternative rows in excel selected table (only visible rows), anyone can you please help me.
Related:

7 responses

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Aug 28, 2009 at 10:59 PM
try this macro (this will color rows 2,4,6,8 etc red)

Sub test()
Dim j As Integer, k As Integer
j = Range("a1").End(xlDown).Row
'j is the last row
For k = 1 To j
If k Mod 2 = 0 Then
Cells(k, "a").EntireRow.Interior.ColorIndex = 3
End If
Next k
End Sub


if you want rows 1,3,5,7 etc to be colored
change the following line in the above macro
If k Mod 2 = 0 Then
into
If k Mod 2 = 1 Then
4
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Sep 1, 2009 at 08:07 PM
quote
I want ALL THE UNHIDDEN rows to be colored.
unquote
why do you want to color the unhidden rows. it is always in front of you anyhow try this mcro

Sub test()
Dim j As Integer, k As Integer
j = Range("a1").End(xlDown).Row
'j is the last row
For k = 1 To j
If Rows(k).Hidden = False Then
Cells(k, "a").EntireRow.Interior.ColorIndex = 3
End If
Next k
End Sub
2
i want to color the rows from A to E alone , so if I write the code above its puts me the color for the entire row , so can u pls advice
0
Hi,

But, I want to fill color in selected range (any range), which rows are visible (Not Hidden). if my rows are 1 to 10, hidden rows 3 and 6, then visible rows 1,2,4,5,7,8,9,10. now I want to alternate color these visible rows.
1
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Aug 31, 2009 at 05:22 AM
contradiction between first message and laest one. first you want ALTERENATE ROWS to be colored. Now you want ALLTHE unhidden rows to be colored . please rephrase your question.
0

Didn't find the answer you are looking for?

Ask a question
I'm very sorry for that, I want ALL THE UNHIDDEN rows to be colored. Please help me. thx
0
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Jun 26, 2012 at 06:26 AM
try this


Sub test()
Dim j As Integer, k As Integer
j = Range("a1").End(xlDown).Row
'j is the last row
For k = 1 To j
If Rows(k).Hidden = False Then
'Cells(k, "a").EntireRow.Interior.ColorIndex = 3
Range(Cells(k, "A"), Cells(k, Columns.Count).End(xlToLeft)).Cells.Interior.ColorIndex = 3

End If
Next k
End Sub
0
Sub Test()
Dim iNumOfRows As Integer, iStartFromRow As Integer, iCount As Integer
iNumOfRows = Range("D61").End(xlDown).Row '--- counts Rows down starting from D61

For iStartFromRow = 61 To iNumOfRows

If Rows(iStartFromRow).Hidden = False Then '--- only unhidden rows matter

iCount = iCount + 1

If iCount - 2 * Int(iCount / 2) = 0 Then
Rows(iStartFromRow).Interior.Color = RGB(220, 230, 241)
Else
Rows(iStartFromRow).Interior.Color = RGB(184, 204, 228)
End If

End If
Next iStartFromRow

End Sub
0