First, ignoring both end-to-end and Else.
I would think that if one of the actual properties of Range.Value contained a hyphen (aka Chr(45 ), and the other does not, then the behavior will not be the same for both of your samples, regardless of whether you got the InStr function syntax correctly . you have enough to define a True / False condition, although I usually use the CBool wrapper around Instr to remind myself that its result is used in a Boolean way.
I believe that your βvalueβ representing a hyphen is actually 6621123 not 6621-123 and that the formatting of the number was applied to the cell (for example, the user number format is 0000-000 . In this case, if you want to determine if a hyphen exists in the displayed value , use Range.Text property.
If CBool(InStr(1, cell.Text, "-")) Then 'hyphen exists as seen on worksheet either in .Value or .Text Else 'hyphen does not exist as seen on worksheet End If
ΒΉ In VBA, False is zero, and for all goals and targets, True is what is not False. Strictly speaking, True in VBA is mathematically treated as (-1), while a TRUE sheet is resolved as 1.
source share