Multiple Conditional Formatting Help - VBA

jacksparrow

New Member
Joined
Feb 12, 2008
Messages
35
Hello all,

I have columns of numbers like so:
A B C D E F
1
2
3


I want to setup some code so that the values in D E F would determine the color for the corresponding values in A B C. So if D1 < 10, then A1 = green, if D1 is between 10 and 20, then A1 = red and so on. E1 would likewise determine B1; F3 would determine C3, etc.

I have this code, but I don't know how to alter it to meet the conditions above. Any help would be appreciated.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim icolor As Integer
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
Select Case Target
Case 1 To 5
icolor = 6
Case 6 To 10
icolor = 12
Case 11 To 15
icolor = 7
Case 16 To 20
icolor = 53
Case 21 To 25
icolor = 15
Case 26 To 30
icolor = 42
Case Else
'Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi jacksparrow
I am wondering why you are using VBA for this when you can just use Conditional Formatting?
As by the sound of it, you only have 3 outcome for each cell.

Thanks
Tigs
 
Upvote 0
Hi


Change the range in the line
Code:
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
to you requirements.
Code:
If Not Intersect(Target, Range("A1:C100")) Is Nothing Then

Change the line
Code:
Select Case Target
to
Code:
Select Case Target.Offset(0, 3)

use the color palette to determine the color code that you want to use
http://dmcritchie.mvps.org/excel/colors.htm

bearing in mind this will only work when you manually change the cell contents in column a b or c not if they are formulas

Thanks
Tigs
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

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