Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Condintional Format Entire Row based on Value in Cell


I have this VBA code (see below) which changes the background color of a
cell based on the value in the cell. What I really want to do is apply
this to the entire row so that say “S5” gives the result “DOG” then the
entire row changes to red. Thanks in advance for any suggestions.


Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPage = Range("A5:S200")
For Each Cell In MyPage

If Cell.Value = "CAT" Then
Cell.Interior.ColorIndex = 4
End If

If Cell.Value = "BIRD" Then
Cell.Interior.ColorIndex = 40
End If

If Cell.Value = "DOG" Then
Cell.Interior.ColorIndex = 3
End If

If Cell.Value = "SNAKE" Then
Cell.Interior.ColorIndex = 10
End If

If Cell.Value < "CAT" And Cell.Value < "BIRD" And Cell.Value
< "DOG" And Cell.Value < "SNAKE" Then
Cell.Interior.ColorIndex = xlNone
End If

Next
End Sub


--
WOLF87654
------------------------------------------------------------------------
WOLF87654's Profile: http://www.thecodecage.com/forumz/member.php?userid=223
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=83449

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Condintional Format Entire Row based on Value in Cell

What about:

Cell.EntireRow.Interior.ColorIndex=....

Regards,
Per

On 7 Apr., 03:43, WOLF87654 wrote:
I have this VBA code (see below) which changes the background color of a
cell based on the value in the cell. What I really want to do is apply
this to the entire row so that say “S5” gives the result “DOG” then the
entire row changes to red. Thanks in advance for any suggestions.

Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPage = Range("A5:S200")
For Each Cell In MyPage

If Cell.Value = "CAT" Then
Cell.Interior.ColorIndex = 4
End If

If Cell.Value = "BIRD" Then
Cell.Interior.ColorIndex = 40
End If

If Cell.Value = "DOG" Then
Cell.Interior.ColorIndex = 3
End If

If Cell.Value = "SNAKE" Then
Cell.Interior.ColorIndex = 10
End If

If Cell.Value < "CAT" And Cell.Value < "BIRD" And Cell.Value
< "DOG" And Cell.Value < "SNAKE" *Then
Cell.Interior.ColorIndex = xlNone
End If

Next
End Sub

--
WOLF87654
------------------------------------------------------------------------
WOLF87654's Profile:http://www.thecodecage.com/forumz/member.php?userid=223
View this thread:http://www.thecodecage.com/forumz/sh...ad.php?t=83449


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Condintional Format Entire Row based on Value in Cell

Just add EntireRow to the Cell reference. For example, where you have
this...

Cell.Interior.ColorIndex = 3

change it to this...

Cell.EntireRow.Interior.ColorIndex = 3

and then do the same modification to the rest of your color assignments.

--
Rick (MVP - Excel)


"WOLF87654" wrote in message
...

I have this VBA code (see below) which changes the background color of a
cell based on the value in the cell. What I really want to do is apply
this to the entire row so that say "S5" gives the result "DOG" then the
entire row changes to red. Thanks in advance for any suggestions.


Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPage = Range("A5:S200")
For Each Cell In MyPage

If Cell.Value = "CAT" Then
Cell.Interior.ColorIndex = 4
End If

If Cell.Value = "BIRD" Then
Cell.Interior.ColorIndex = 40
End If

If Cell.Value = "DOG" Then
Cell.Interior.ColorIndex = 3
End If

If Cell.Value = "SNAKE" Then
Cell.Interior.ColorIndex = 10
End If

If Cell.Value < "CAT" And Cell.Value < "BIRD" And Cell.Value
< "DOG" And Cell.Value < "SNAKE" Then
Cell.Interior.ColorIndex = xlNone
End If

Next
End Sub


--
WOLF87654
------------------------------------------------------------------------
WOLF87654's Profile:
http://www.thecodecage.com/forumz/member.php?userid=223
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=83449


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
conditional format of entire row based on a single cell in row CEG_Staffer[_2_] Excel Worksheet Functions 7 July 16th 09 10:54 PM
Conditional format an entire row based on one cell Wagman V1 Excel Worksheet Functions 3 August 9th 08 12:09 AM
Conditional format based on entire row LisaVH Excel Worksheet Functions 8 January 17th 07 07:29 PM
Conditional Format to change entire row based on one cells data Crowbar via OfficeKB.com Excel Discussion (Misc queries) 2 October 25th 05 04:01 PM
Can I format an entire row based on the value of a single cell? LTShelley Excel Discussion (Misc queries) 1 August 11th 05 07:37 PM


All times are GMT +1. The time now is 07:22 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"