Sunday, May 3, 2020

Conditional formatting using VBA

Option Explicit


Sub conditionalfinal()
Sheets("conditionalformattingvba").Select
'Range("G1").Select
'
'Range(Selection, Selection.End(xlDown)).Select
'Range(Selection, Selection.End(xlToRight)).Select
'
Dim workingrange, cell As Range

'Set workingrange = Selection
'


'MsgBox (workingrange.Address)

'Dim workingrange As Range
'Set workingrange = Application.InputBox(Title:="Select the range for conditionalformatting", Prompt:="select the range", Type:=8)
'MsgBox (workingrange.Address)

'Sheets("conditionalformatting").Select
'Range("I5").CurrentRegion.Select
'
'Set workingrange = Selection
'
'
'
'MsgBox (workingrange.Address)

Sheets("conditionalformatting").Select
Range("I2:N19").Select
Set workingrange = Selection
MsgBox (workingrange.Address)


For Each cell In workingrange
If InStr(1, cell.Value, "North", vbTextCompare) > 0 Then
cell.Interior.ColorIndex = 3
cell.Font.ColorIndex = 19
ElseIf InStr(1, cell.Value, "South", vbTextCompare) > 0 Then
cell.Interior.ColorIndex = 23
cell.Font.ColorIndex = 2
ElseIf InStr(1, cell.Value, "West", vbTextCompare) > 0 Then
cell.Interior.ColorIndex = 4
cell.Font.ColorIndex = 30
ElseIf InStr(1, cell.Value, "East", vbTextCompare) > 0 Then
cell.Interior.ColorIndex = 27
cell.Font.ColorIndex = 1
Else
cell.ClearFormats
End If




Next cell





End Sub

No comments:

Post a Comment