Color Cells based on Loop

cgsamaras

New Member
Joined
Nov 24, 2009
Messages
2
What would be the best way to go about coloring every 17 rows (rows 4:416 - columns C:V), skipping a row in between each 16 rows. Need the background color to be blue. So basically - every 17R x 20C should be blue skipping 1 x row in between each set of 17 rows from row 4 to row 416.

Appreciate any help you can provide.

Thanks,
Chris
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Welcome to MrExcel board...

Are you wanting a VBA solution? And just to clarify you want to color 17 rows, leave one uncolored, then color the next 17 and so on through the designated range?
 
Upvote 0
Yes. I am looking to do this in VBA and the only way I have found to get it working is making a macro that goes through each range as so -

Range("C4:V20").Select
Selection.Interior.ColorIndex = 37
Selection.Font.ColorIndex = 49
Range("C22:V38").Select
Selection.Interior.ColorIndex = 37
Selection.Font.ColorIndex = 49

and so on and so on....

I know there has to be a much better way.

Any help would be awesome!

Thanks
 
Upvote 0
Please note that the worksheet is not qualified, so this will run against the active sheet.

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br>    <br><SPAN style="color:#00007F">Sub</SPAN> exa()<br><SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> i = 4 <SPAN style="color:#00007F">To</SPAN> 400 <SPAN style="color:#00007F">Step</SPAN> 18<br>        <SPAN style="color:#00007F">With</SPAN> Range(Cells(i, "C"), Cells(i + 16, "V"))<br>            .Interior.ColorIndex = 37<br>            .Font.ColorIndex = 49<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

Mark
 
Upvote 0

Forum statistics

Threads
1,215,223
Messages
6,123,711
Members
449,118
Latest member
MichealRed

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