Cond. Formatting

RoyinUK2000

Board Regular
Joined
Mar 26, 2002
Messages
79
I would like to colour rows depending on six different values. Can someone please tell me how to apply conditional formatting for say six values in vb.

Thanks
Roy
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
On 2002-04-29 03:31, RoyinUK2000 wrote:
I would like to colour rows depending on six different values. Can someone please tell me how to apply conditional formatting for say six values in vb.

Thanks
Roy

You will need to use an event for this.
What is the criteria, colour & range to monitor....
 
Upvote 0
The range of cells is A to H and is growing downwards. The B column will contain a value of either ACID ALKALINE SULPHONE NON-HAZ REBLEND. I want the rows to be different colours dependant on what is in column B. I can do this for 3 values in excel but want to know how to do this for more than 3 values by using code.

Thx
Roy
 
Upvote 0
Based on the eight column table (A:H) and with five conditions for the product type (in column B), this code will colour format the records, driven by the Worksheet_Change event. Because of the Select Case statement, you can have actually as many conditions as you wish:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim prodType As String
Application.EnableEvents = False
If Target.Column = 8 Then
ActiveCell.Offset(0, -7).Select
prodType = ActiveCell
Range(ActiveCell.Offset(0, -1), ActiveCell.Offset(0, 6)).Select

Select Case prodType
Case "ACID"
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "ALKALINE"
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "SULPHONE"
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "NON-HAZ"
With Selection.Interior
.ColorIndex = 10
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Case "REBLEND"
With Selection.Interior
.ColorIndex = 12
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Select
ActiveCell.Offset(1, 0).Select
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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