VBA code for if statement referencing to a list

NoxGalleon106

New Member
Joined
Oct 15, 2016
Messages
29
Hi,

Can someone help me on the coding of the below condition? basically, ActiveCell.Offset(0, 25).Value should be equal to "Asia" if the activecell in column F contains the below list and ActiveCell.Offset(0, 25) is blank.

list: (note that the text can have XXX at the end of the word, so it is more like a contains condition)
HK
SG
CN
AU
JP


If ActiveCell.Value =list And ActiveCell.Offset(0, 25).Value = "" Then
ActiveCell.Offset(0, 25).Value = "Asia"
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
Code:
Sub IfInList()

    Dim Cnt As Long
    Dim Arr As Variant
    
    Arr = Array("HK", "SG", "CN", "AU", "JP")
    
    With ActiveCell
        If UBound(Filter(Arr, .Value, False, vbTextCompare)) >= 0 _
            And Len(.Offset(, 25).Value) = 0 Then
            .Offset(, 25).Value = "Asia"
        End If
    End With

End Sub
 
Upvote 0
Hi,

Thanks for your help but it is currently not working. All the cells are having "Asia" even if the active cell does not contain those values in array.
It should only show as "Asia" if it contains the values in array and the activecell.offset(0,25).value = ""
 
Upvote 0
Apologies, it should be
Code:
Sub IfInList()

    Dim Cnt As Long
    Dim Arr As Variant
    
    Arr = Array("AU", "CN", "HK", "JP", "SG")
    
    With ActiveCell
        If UBound(Filter(Arr, Left(.Value, 2), , vbTextCompare)) >= 0 _
            And Len(.Offset(, 25).Value) = 0 Then
            .Offset(, 25).Value = "Asia"
        End If
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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