Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,661
- Office Version
- 365
- 2016
- Platform
- Windows
I have this line of code that is meant to determine where in a string (value at ws_ifm.cells(trow,2)), a substring (host) starts. Everything works except when the value in the cell equals the value of host.
eg - ws_ifm.cells(trow,2).value = "Cheese", and host = "Cheese"
The code returns a value of 0 which would suggest the sub string doesn't exist in the main string, which in reality, the substring is the main string.
Is there a way to change this code to capture this (I would think the formula would return a value of 1). Or should I just test if the values are equal first?
eg - ws_ifm.cells(trow,2).value = "Cheese", and host = "Cheese"
The code returns a value of 0 which would suggest the sub string doesn't exist in the main string, which in reality, the substring is the main string.
Is there a way to change this code to capture this (I would think the formula would return a value of 1). Or should I just test if the values are equal first?
VBA Code:
startPosition = InStr(1, ws_ifm.Cells(trow, 2), host, vbTextCompare)
If startPosition = 0 Then
'... execute code recognizing the value of host does not exist in the cell value