Add an "or" command to vba

Dabaron2321

New Member
Joined
Jan 20, 2016
Messages
9
Hi, I have a macro that conditional formats a cell depending on the country it contains. What I need though is a way so that a particular colour scheme can apply to more than one country. So basically if A1 = "Sweden" "TRUE "FALSE" can become if A1= "Sweden" or "Ukraine" or "Barbados" "TRUE "FALSE" for example.

Here is the code:

<code> </code><code>
Code:
 Range("A1:ah60").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=IF(A1=""Bosnia & Herzegovina"",TRUE,FALSE)"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = RGB(0, 0, 0)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 15
        .Gradient.ColorStops.Clear
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
        .Color = RGB(0, 0, 225)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.07)
        .Color = RGB(0, 0, 225)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.1)
        .Color = RGB(255, 255, 0)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.13)
        .Color = RGB(255, 255, 0)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.16)
        .Color = RGB(0, 0, 225)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.19)
        .Color = RGB(0, 0, 225)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0.22)
        .Color = RGB(245, 255, 255)
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
        .Color = RGB(245, 255, 255)
        .TintAndShade = 0
    End With
    
    
End Sub
</code><code>
Any help appreciated!</code>
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,860
Office Version
365
Platform
Windows
How about
Code:
        "=or(A1=""Sweden"",A1=""Ukraine"", a1=""Barbados"")"
 

Dabaron2321

New Member
Joined
Jan 20, 2016
Messages
9
Thanks for your reply, could you demonstrate how i would inset that into my code above as wherever i try and place it comes up with errors.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,860
Office Version
365
Platform
Windows
Like
Code:
<code>Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=or(A1=""Sweden"",A1=""Ukraine"", a1=""Barbados"")"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority</code>
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,860
Office Version
365
Platform
Windows
Glad to help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,089,946
Messages
5,411,446
Members
403,370
Latest member
Massi_921

This Week's Hot Topics

Top