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>
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
How about
Code:
        "=or(A1=""Sweden"",A1=""Ukraine"", a1=""Barbados"")"
 
Upvote 0
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.
 
Upvote 0
Like
Code:
<code>Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=or(A1=""Sweden"",A1=""Ukraine"", a1=""Barbados"")"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority</code>
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,403
Members
452,325
Latest member
BlahQz

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