0

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

2
  • Case select would be best for this. Commented Oct 30, 2017 at 17:12
  • 2
    since you are repeating the same code multiple times consider writing a function and calling that. Commented Oct 30, 2017 at 17:30

1 Answer 1

1

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

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

1 Comment

Your similar question is foo bar. This is a VBA question, not a VB.NET question.

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.