Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Subject - Loop/Conditional formatting 3 cells above. - more than 3

I have the following code which changes the color of the cell based on its
value.
Now I need to color not only that particular cell, but also 3 cells above
it. How can I put it in a loop.

This is my code.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1:AQ120")) Is Nothing Then
Select Case Target

Case Is = "A"
icolor = 38
Case Is = "B"
icolor = 38
Case Is = "C"
icolor = 35
Case Is = "D"
icolor = 36
Case Is = "E"
icolor = 39
Case Is = "F"
icolor = 35
Case Is = "G"
icolor = 37
Case Is = "H"
icolor = 34
Case Is = "I"
icolor = 40
Case Is = "J"
icolor = 40
Case Is = "K"
icolor = 34
Case Is = "L"
icolor = 34
Case Is = "M"
icolor = 34
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Subject - Loop/Conditional formatting 3 cells above. - more than 3

If the three cells above Z100 are Z99, Z98, and Z97 then

Instead of:
Target.Interior.ColorIndex = icolor
use something like
Dim r as Range
Set r=Range(Target, Target.Offset(-3,0))
r.Interior.ColorIndex = icolor
--
Gary's Student


"Rajula" wrote:

I have the following code which changes the color of the cell based on its
value.
Now I need to color not only that particular cell, but also 3 cells above
it. How can I put it in a loop.

This is my code.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1:AQ120")) Is Nothing Then
Select Case Target

Case Is = "A"
icolor = 38
Case Is = "B"
icolor = 38
Case Is = "C"
icolor = 35
Case Is = "D"
icolor = 36
Case Is = "E"
icolor = 39
Case Is = "F"
icolor = 35
Case Is = "G"
icolor = 37
Case Is = "H"
icolor = 34
Case Is = "I"
icolor = 40
Case Is = "J"
icolor = 40
Case Is = "K"
icolor = 34
Case Is = "L"
icolor = 34
Case Is = "M"
icolor = 34
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

End Sub

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
Loop/Conditional formatting 3 cells above - More than 3 conditions Rajula Excel Programming 4 October 11th 06 11:20 AM
formatting cells loop Ciara Excel Programming 3 September 12th 06 05:20 PM
Conditional Formatting in For:Next loop - won't work!!! Cumberland[_3_] Excel Programming 3 June 21st 06 01:03 PM
Conditional Formatting in a Loop lost!! Excel Programming 8 October 6th 04 02:43 PM
conditional formatting & a loop lost!! Excel Programming 1 September 27th 04 08:59 PM


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