Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 带多个字符串的VBA InStr_String_Vba_If Statement - Fatal编程技术网

String 带多个字符串的VBA InStr

String 带多个字符串的VBA InStr,string,vba,if-statement,String,Vba,If Statement,我想用InStr检查多个字符串,并在必要时替换它们 比如: 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 我相信有一种更简单、更直观的方法可以做到这一点,但我不知

我想用InStr检查多个字符串,并在必要时替换它们

比如:

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
我相信有一种更简单、更直观的方法可以做到这一点,但我不知道怎么做。 可能是环还是壳

提前感谢

用例是一个解决方案

阵列是另一种解决方案。可以将值填充到数组中,并对数组中的每个值执行For循环

对类似问题的答复:


案例选择将是最好的。因为你多次重复相同的代码,考虑写一个函数并调用它。你的类似问题是Foobar。这是一个VBA问题,不是VB.NET问题。