Conditional Formatting

Y

yclhk

How to include more than 3 conditions for formatting the cell ?
For example: if the cell values are A, B, C, D or E, the cell displays in a
designated format.
 
D

David Biddulph

If you do mean that you want one designated format if the cell value is A,
B, C, D, or E, then you can use an OR function in your conditional
formatting condition. Use Formula Is, not Cell Value Is.
 
G

Gary

I use a For-Next loop for this.

Place code behind worksheet -

Presumes your data is in Column G, rows 2-500

For rwIndex = 2 To 500
For colIndex = 6 To 6
With Worksheets("Your Tab Name").Cells(rwIndex, colIndex)
If .Value = "A" Then
.Font.ColorIndex = 3
Else
If .Font.ColorIndex = B Then
.Font.ColorIndex = 4
Else

End If
End If
End With
Next colIndex
Next rwIndex


hth
 
G

Gord Dibben

You could use event code to get more than 3 formats for a cell.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Range
Set vRngInput = Intersect(Target, Range("A1"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case UCase(rng.Value)
Case Is = "A": Num = 10 'green
Case Is = "B": Num = 1 'black
Case Is = "C": Num = 5 'blue
Case Is = "D": Num = 7 'magenta
Case Is = "E": Num = 46 'orange
Case Is = "F": Num = 3 'red
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the code into that sheet module. Alt + q to go back to Exel window.

Adjust range and colors to suit.


Gord Dibben MS Excel MVP
 
Y

yclhk

Thanks for all. I think the solution of using OR function is more simple.
However, how to compose the formula in this formatting ?

Thanks again for your help,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top