Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
Hi,
I'm trying to write a macro that will set a different background color for every other row of the selection (not of the whole worksheet). I figured that I would just need to loop through each cell of the selection, test whether it's in an even-number row, and if so, set its background color. So if the selection covers 3 columns, every other set of 3 cells in the selection would get a background color. But... there doesn't seem to be a property to test the row number of a given cell! So how could I work this out? Thanks in advance for your help. Raph |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
this should work fine:
Sub test() For Each row_ In Selection.Rows If row_.Row() Mod 2 = 1 Then row_.Interior.ColorIndex = 35 End If Next row_ End Sub you might want to change the if-statement, now it always colors the uneven rows, if you want to start coloring the second row of your selection you should change it! hth Carlo " wrote: Hi, I'm trying to write a macro that will set a different background color for every other row of the selection (not of the whole worksheet). I figured that I would just need to loop through each cell of the selection, test whether it's in an even-number row, and if so, set its background color. So if the selection covers 3 columns, every other set of 3 cells in the selection would get a background color. But... there doesn't seem to be a property to test the row number of a given cell! So how could I work this out? Thanks in advance for your help. Raph |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
You can use Conditional formatting for the required selection with this
formula: =MOD(ROW(),2)=0 Regards, Stefi € ezt Ã*rta: Hi, I'm trying to write a macro that will set a different background color for every other row of the selection (not of the whole worksheet). I figured that I would just need to loop through each cell of the selection, test whether it's in an even-number row, and if so, set its background color. So if the selection covers 3 columns, every other set of 3 cells in the selection would get a background color. But... there doesn't seem to be a property to test the row number of a given cell! So how could I work this out? Thanks in advance for your help. Raph |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
No need for a macro, use conditional formatting, see
http://www.xldynamic.com/source/xld.CF.htmlrows -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) wrote in message ups.com... Hi, I'm trying to write a macro that will set a different background color for every other row of the selection (not of the whole worksheet). I figured that I would just need to loop through each cell of the selection, test whether it's in an even-number row, and if so, set its background color. So if the selection covers 3 columns, every other set of 3 cells in the selection would get a background color. But... there doesn't seem to be a property to test the row number of a given cell! So how could I work this out? Thanks in advance for your help. Raph |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
Carlo wrote:: For Each row_ In Selection.Rows Aargh, of course! I didn't even think that a Selection has a Rows collection! Thank you very much! Raph |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
Looks like the # got stripped from Bob's link.
http://www.xldynamic.com/source/xld.CF.html#rows Zilbandy wrote: On Fri, 15 Sep 2006 09:08:18 +0100, "Bob Phillips" wrote: No need for a macro, use conditional formatting, see http://www.xldynamic.com/source/xld.CF.htmlrows Link doesn't work for me. :( -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
Stefi wrote: You can use Conditional formatting for the required selection with this formula: =MOD(ROW(),2)=0 Conditional formatting is defined according to the cell's value, not to a testing formula... Where should I input the formula? Raph |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Background color for every other row
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Checkbox to change background color, font color and remove/ add bo | Excel Discussion (Misc queries) | |||
how can I conditionally change font color, or background color? | Excel Worksheet Functions | |||
Cell background color (interior color) setting not working | Excel Programming | |||
Default Border, Font Color, and Cell Background Color | Excel Discussion (Misc queries) | |||
Excel 2003 Font Color and Background Color | Excel Discussion (Misc queries) |