ifand conditional formating

A1058

New Member
Joined
Sep 13, 2006
Messages
46
how can something like this be formatted to be working???
any help would be greatly appreciated

If Range("$A$42" > 0) And
Range("$A$42" < 1) Then
Range(H12) .Interior.ColorIndex = "yellow"
If Range("$A$42" > 1) And
Range("$A$42" < 2) Then
Range(H12:H13) .Interior.ColorIndex = "yellow"
If Range("$A$42" > 2) And
Range("$A$42" < 3) Then
Range(H12:H14) .Interior.ColorIndex = "yellow"
End If
End If
End If
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Have you looked at Conditional formatting?

look under Format>Conditional Formatting
 
Upvote 0
am needing to achieve this using VBA this time... thanks for quick reply. anyone have any ideas how this needs to be written using VBA?
 
Upvote 0
try this

Code:
If [a42].Value > 0 And [a42].Value < 1 Then
[h12].Interior.ColorIndex = 6
Else: [h12].Interior.ColorIndex = 0
End If
If [a42].Value > 1 And [a42].Value < 2 Then
[h13].Interior.ColorIndex = 6
Else: [h13].Interior.ColorIndex = 0
End If
If [a42].Value > 2 And [a42].Value < 3 Then
[h14].Interior.ColorIndex = 6
Else: [h14].Interior.ColorIndex = 0
End If

HTH
 
Upvote 0
thanks for the reply. i edited what you wrote to fit my needs. and it works pretty good, it looks like whats below. although if A42's value changes the colors in the target cells do not update to what they should. not a huge problem because they should not change often.but would be nice if they did update if the value in a42 changes.... any ideas on that part of it???

If [a42].Value <= 0 Then
[h12:h14].Interior.ColorIndex = 0
End If
If [a42].Value > 0 And [a42].Value < 1 Then
[h12].Interior.ColorIndex = 6
End If
If [a42].Value > 1 And [a42].Value < 2 Then
[h12:h13].Interior.ColorIndex = 6
End If
If [a42].Value > 2 And [a42].Value < 3 Then
[h12:h14].Interior.ColorIndex = 6
End If
 
Upvote 0
try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 42 And Target.Column = 1 Then
If [a42].Value <= 0 Then
[h12:h14].Interior.ColorIndex = 0
End If
If [a42].Value > 0 And [a42].Value < 1 Then
[h12].Interior.ColorIndex = 6
End If
If [a42].Value > 1 And [a42].Value < 2 Then
[h12:h13].Interior.ColorIndex = 6
End If
If [a42].Value > 2 And [a42].Value < 3 Then
[h12:h14].Interior.ColorIndex = 6
End If
Else: Exit Sub
End If
End Sub

you need to paste this code into the sheet you are using it on, right click the sheet tab and select view code, paste it there,

HTH
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,240
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top