Hi,
I have a slight problem using InStr in VBA, code below:
The 3 different text values are taken from cells on the worksheet.
The problem is that if the text value appears at the start of an iRange, sometimes InStr gives '0' as its position in the string. I do not know why this would be, surely it should be '1'?? Also, sometimes if the text value is a single letter say, which appears more than once, InStr can give different results, seemingly depending on what mood it's in...
This is causing issues because even when the text does appear in iRange, it returns a '0' and then doesn't call the Insert_Checkbox sub. Is this a problem with InStr or have I missed something?
Thanks,
H
I have a slight problem using InStr in VBA, code below:
Code:
Dim Text1, Text2, Text3 as String
For Each iRange In Range("Org_List")
If InStr(1, iRange.Value, Text1) <> 0 And Text1 <> "" Then
Call Insert_Checkbox(iRange.Row)
Else
If InStr(1, iRange.Value, Text2) <> 0 And Text2 <> "" Then
Call Insert_Checkbox(iRange.Row)
Else
If InStr(1, iRange.Value, Text3) <> 0 And Text3 <> "" Then
Call Insert_Checkbox(iRange.Row)
End If
End If
End If
Next iRange
The 3 different text values are taken from cells on the worksheet.
The problem is that if the text value appears at the start of an iRange, sometimes InStr gives '0' as its position in the string. I do not know why this would be, surely it should be '1'?? Also, sometimes if the text value is a single letter say, which appears more than once, InStr can give different results, seemingly depending on what mood it's in...
This is causing issues because even when the text does appear in iRange, it returns a '0' and then doesn't call the Insert_Checkbox sub. Is this a problem with InStr or have I missed something?
Thanks,
H