OzGrid

How to use IF THEN to select a specific case (region)

< Back to Search results

 Category: [Excel]  Demo Available 

How to use IF THEN to select a specific case (region)

 

Requirement:

 

The user has a few arrays made up of country codes, each array represents a region.

The user needs to  use a select case statement to correctly select the correct region (array) for any given country code.


The user would like to have a country code and then using select case look inside each array and if it finds a match then thats the region?

 

Solution:

Code:
Sub a()
Origin = Cells(1, 1).Value
ASPA = "CN,AU,HK"
EMEA = "DE,SE,GB"
If InStr(ASPA, Origin) > 0 Then
    Region = "Asia"
ElseIf InStr(EMEA, Origin) > 0 Then
    Region = "Europe"
ElseIf Origin = "US" Then
    Region = "US"
End If
MsgBox Region
End Sub

Obtained from the OzGrid Help Forum.

Solution provided by Patel.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

 

How to test if named range exists
How to combine IF/AND statements
How to hide and unhide with checkboxes - multiple checkboxes do multiple different things

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 


Gallery