0

I need to loop though a cell range that contains one or several locale ISO codes in a CSV fashion e.g esES, frFR, itIT, etc.

If ANY of these values are contained within a cell, I select it and paste it to another workbook. The latter part I got covered, but I can't figure how to make the former part work. This is the code I'm working with at the moment:

OTHERS_V = "*arAR*|*bgBG*|*csCZ*|*daDK*"

For Each cell In Intersect(Sheets("Requests").Range("G:G"), Sheets("Requests").UsedRange)
        If cell.Value Like OTHERS_V Then [...]

I'm pretty new to VBA and I don't know much about Regex in this language but from my experience this should read something like:

(anything + "arAR" + anything) OR (anything + "bgBG" + anything) OR [...]

etc.

It doesn't seem to work though. How would you go about accomplishing what I'm after in this context?

1
  • Make OTHERS_V and array not a string and loop through the array and do your like test on each one. Commented Jul 22, 2016 at 14:11

1 Answer 1

1

As per my comments, put OTHERS_V list in an array and loop testing each one:

Sub fooo()
Dim OTHERS_V()
Dim cell As Range
Dim i As Long

OTHERS_V = Array("*arAR*", "*bgBG*", "*csCZ*", "*daDK*")

For Each cell In Intersect(Sheets("Requests").Range("G:G"), Sheets("Requests").UsedRange)
    For i = LBound(OTHERS_V) To UBound(OTHERS_V)
        If cell.Value Like OTHERS_V(i) Then
            'do your stuff
            Exit For
        End If
    Next i
Next cell


End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.