Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox to change background color, font color and remove/ add bo Sara Excel Discussion (Misc queries) 2 May 1st 23 11:43 AM
how can I conditionally change font color, or background color? MOHA Excel Worksheet Functions 3 August 21st 06 06:57 PM
Cell background color (interior color) setting not working Martin E. Excel Programming 1 May 21st 06 07:00 PM
Default Border, Font Color, and Cell Background Color Elijah Excel Discussion (Misc queries) 1 October 28th 05 04:10 PM
Excel 2003 Font Color and Background Color DrankPA6 Excel Discussion (Misc queries) 1 August 12th 05 11:43 PM


All times are GMT +1. The time now is 12:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"