Reputation: 7
One more similar question about insert color use for each Loop.
Question: the photo contains monthly sale amounts for 40 sales regions.write a sub that uses a for loop to color the interior of every other row(row 3,5,etc) gray. Color only the date area, column A TO M
http://postimg.org/image/vhvj83wwd/
Now I select the whole currentregion and but I didn't know how to select every other row become grey
My code is below:
Sub color()
Dim rngcolor As Range, rngcolors As Range, shtcolor As Worksheet
Set shtcolor = Application.Workbooks("Sales Data").Worksheets("sheet1")
Set rngcolors = shtcolor.Range("a1").CurrentRegion
Set rngcolors = rngcolors.Offset(1, 1).Resize(, rngcolors.Columns.Count - 1)
rngcolors.Select
For Each rngcolor In rngcolors
rngcolor.Font.Interior = vbgrey
Else
Next rngcolor
End Sub
Thank you very much! If you can help me , i have one more similar question insert color , For each loop i hope you can help me either!!!!! Thanks!!!
Upvotes: 0
Views: 155
Reputation: 33145
You can use a For.Next loop with a step
For i = rngcolor.Cells(1).Row to rngcolor.Cells(rngcolor.Cells.Count).Row Step 2
or you can test the row number in a For.Each loop
If rngcolor.Row Mod 2 = 1 Then
Upvotes: 1