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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

big_mac

Board Regular
Joined
Jul 21, 2006
Messages
167
Have you looked at Conditional formatting?

look under Format>Conditional Formatting
 

A1058

New Member
Joined
Sep 13, 2006
Messages
46
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?
 

shippey121

Well-known Member
Joined
Mar 21, 2006
Messages
1,001
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
 

A1058

New Member
Joined
Sep 13, 2006
Messages
46
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
 

shippey121

Well-known Member
Joined
Mar 21, 2006
Messages
1,001
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
 

Forum statistics

Threads
1,136,697
Messages
5,677,270
Members
419,683
Latest member
MrVBAConfused

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
Top