rosi97
rosi97

Reputation: 245

VBA InStr with multiple Strings

I want to check multiple strings with InStr and replace them if necessary.

Something like:

s1 = "ABC"  s2 = "ABCD" s3 = "ABCDE"

If InStr(s1,"D") <> 0 Then
   s1 = ""
End If
If InStr(s2,"D") <> 0 Then
   s2 = ""
End If
If InStr(s3,"D") <> 0 Then
   s3 = ""
End If

I'm sure there is a easier and more intuitive way to do this but i just dont know how.
Maybe with Loop or Case ?

Thanks in Advance

Upvotes: 0

Views: 2245

Answers (1)

user8753746
user8753746

Reputation:

Using Case is a solution.

Array is another solution. You can populate your values to an array and do a For Loop for each value in the array.

Answer to similar question:

InStr array is in string

Upvotes: 1

Related Questions