Jus*_* L. 5 excel vba excel-vba
我有条件似乎不起作用.
If Not InStr(1, cell.Value, "-") Then
'Do Something
Else
'Do something else
End If
Run Code Online (Sandbox Code Playgroud)
cell.Value电子表格中带有短划线的数字在哪里:"6621-123",或没有短划线:"555321"
第一个If让我们通过和Else被忽略.任何想法为什么这不起作用?
InStr返回0不匹配(不是-1,因为VBA字符串索引是基于1)并且not 0是true(-1); 所有其他可能的值> 0都可以返回.
If InStr(1, cell.Value, "-") = 0 Then
'// not present
Else
'// present
Run Code Online (Sandbox Code Playgroud)