Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Fill Color each Row based on a Condition

I have a spreadsheet with customer's account numbers in column A and other
data associated with the account number through column Z.

I'm looking for a way to use the fill color (gray) for the entire row if the
account numbers match, then for the next match use fill color (white) and so
on.

A
1 12345 gray
2 12345 gray
3 12345 gray
4 67891 white
5 67891 white
6 57842 gray
7 54123 white
8 54123 white

Thanks in advance for the help.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Fill Color each Row based on a Condition

Donnie,

Try the following code

Sub ColorGray()
Dim Rng As Range
Dim OldVal As Variant
Dim Gray As Boolean

Gray = True
OldVal = Range("A1").Value
For Each Rng In Range("A1:A10") ' CHANGE TO CORRECT RANGE
If Rng.Value = OldVal Then
If Gray Then
Rng.EntireRow.Interior.ColorIndex = 15
Else
Rng.EntireRow.Interior.ColorIndex = 2
End If
Else
OldVal = Rng.Value
Gray = Not Gray
If Gray Then
Rng.EntireRow.Interior.ColorIndex = 15
Else
Rng.EntireRow.Interior.ColorIndex = 2
End If
End If
Next Rng
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Donnie Stone" wrote in message
...
I have a spreadsheet with customer's account numbers in column A and other
data associated with the account number through column Z.

I'm looking for a way to use the fill color (gray) for the entire row if

the
account numbers match, then for the next match use fill color (white) and

so
on.

A
1 12345 gray
2 12345 gray
3 12345 gray
4 67891 white
5 67891 white
6 57842 gray
7 54123 white
8 54123 white

Thanks in advance for the help.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Fill Color each Row based on a Condition

Chip,

Works great, I appreciate the help!

Donnie

"Chip Pearson" wrote in message
...
Donnie,

Try the following code

Sub ColorGray()
Dim Rng As Range
Dim OldVal As Variant
Dim Gray As Boolean

Gray = True
OldVal = Range("A1").Value
For Each Rng In Range("A1:A10") ' CHANGE TO CORRECT RANGE
If Rng.Value = OldVal Then
If Gray Then
Rng.EntireRow.Interior.ColorIndex = 15
Else
Rng.EntireRow.Interior.ColorIndex = 2
End If
Else
OldVal = Rng.Value
Gray = Not Gray
If Gray Then
Rng.EntireRow.Interior.ColorIndex = 15
Else
Rng.EntireRow.Interior.ColorIndex = 2
End If
End If
Next Rng
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Donnie Stone" wrote in message
...
I have a spreadsheet with customer's account numbers in column A and

other
data associated with the account number through column Z.

I'm looking for a way to use the fill color (gray) for the entire row if

the
account numbers match, then for the next match use fill color (white)

and
so
on.

A
1 12345 gray
2 12345 gray
3 12345 gray
4 67891 white
5 67891 white
6 57842 gray
7 54123 white
8 54123 white

Thanks in advance for the help.






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
How can I automatically color a cell based upon a condition being RBober2 Excel Worksheet Functions 4 September 26th 09 09:14 PM
Fill a cell based on a condition being met confused teacher Excel Worksheet Functions 3 July 5th 06 08:29 AM
Change row color based on condition of celss B G Excel Worksheet Functions 3 June 28th 06 08:56 PM
I want to fill the cell color based upon the other cell condition sri Excel Discussion (Misc queries) 4 January 12th 06 01:47 PM
Color Change in chart based of condition KRT Charts and Charting in Excel 1 July 1st 05 12:51 PM


All times are GMT +1. The time now is 03:24 PM.

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"