R
Rakesh Rampiar
How do I represent the following in an event calculate type macro?
If Case Is equalt to and between 5 and -5 change colour to blue
If Case Is equal to and between 10 and -10 change colour to Green
If Case Is equal to and between 20 and -20 change colour to Yellow
etc, etc, etc...
or
If Case is equal to and between 0 and 5 change colour to blue
If Case is equal to and between -5 and 0 change colour to blue
If Case equal to and between 6 and 10 change colour to Green
If Case equal to and between -10 and -6 change colour to Green
If Case equal to and between 11 and 20 change colour to Yellow
If Case equal to and between -20and -11 change colour to Yellow
etc, etc, etc...
Below is the event macro that I wanted to update with the above mentioned
paramaters:
Private Sub Worksheet_Calculate()
Dim myCell As Range
Dim myRng As Range
Dim myColorIndex As Long
Set myRng = Me.Range("d2:h24")
For Each myCell In myRng.Cells
If IsNumeric(myCell.Value) Then
Select Case myCell.Value
Case Is < 1: myColorIndex = 0 'White
Case Is = 1: myColorIndex = 5 'Blue
Case Is <= 2: myColorIndex = 4 'Green
Case Is <= 3: myColorIndex = 6 'Yellow
Case Is <= 4: myColorIndex = 46 'Orange
Case Is <= 5: myColorIndex = 3 'Red
Case Else
myColorIndex = xlNone
End Select
Else
myColorIndex = xlNone
End If
myCell.Interior.ColorIndex = myColorIndex
Next myCell
End Sub
Thank you
Rakesh Rampiar
If Case Is equalt to and between 5 and -5 change colour to blue
If Case Is equal to and between 10 and -10 change colour to Green
If Case Is equal to and between 20 and -20 change colour to Yellow
etc, etc, etc...
or
If Case is equal to and between 0 and 5 change colour to blue
If Case is equal to and between -5 and 0 change colour to blue
If Case equal to and between 6 and 10 change colour to Green
If Case equal to and between -10 and -6 change colour to Green
If Case equal to and between 11 and 20 change colour to Yellow
If Case equal to and between -20and -11 change colour to Yellow
etc, etc, etc...
Below is the event macro that I wanted to update with the above mentioned
paramaters:
Private Sub Worksheet_Calculate()
Dim myCell As Range
Dim myRng As Range
Dim myColorIndex As Long
Set myRng = Me.Range("d2:h24")
For Each myCell In myRng.Cells
If IsNumeric(myCell.Value) Then
Select Case myCell.Value
Case Is < 1: myColorIndex = 0 'White
Case Is = 1: myColorIndex = 5 'Blue
Case Is <= 2: myColorIndex = 4 'Green
Case Is <= 3: myColorIndex = 6 'Yellow
Case Is <= 4: myColorIndex = 46 'Orange
Case Is <= 5: myColorIndex = 3 'Red
Case Else
myColorIndex = xlNone
End Select
Else
myColorIndex = xlNone
End If
myCell.Interior.ColorIndex = myColorIndex
Next myCell
End Sub
Thank you
Rakesh Rampiar