We help IT Professionals succeed at work.

InStr looking for spaces does not give the expected result

95 Views
Last Modified: 2018-10-20
I am getting old but somehow the following code does not yield the desired result:

xName = "Steven Murray Thomas"
MsgBox InStr(1,xName," ")

gives zero and not the expected 7. Any help why?
Thank you so much Michael
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
No. It works fine for me - with a direct copy-paste - returns 7.
President / Owner
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Dale FyeOwner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
Or simply put this statement and see what number it returns. If it doesn't return 32, that means the white space is not the space character.

MsgBox Asc(Mid(xName, 7, 1))

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Or just delete your old code and copy-paste your own code here at top … that was what I did.

Author

Commented:
Thank you so much to all of you. It was indeed as Jim said. It as not a space but a ASCI 160 - I now simply replaced it with CHR(32) and it works fine! Thank you.. Cheers Michael