Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Detecting the space character
Hi All,
I am trying to detect the space character in a string but my code is not working. Thanks for your help. JN sub demo() Dim strlength As Integer Dim str As String str = "good morning" strlength = Len(Trim(str)) For i = 1 To strlength If Mid(str, i, strlength) = Chr(32) Then MsgBox "space" End If Next i End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Detecting the space character
If Mid(str, i, strlength)
should be If Mid(str, i, 1) Start in position i for 1 character. JN wrote: Hi All, I am trying to detect the space character in a string but my code is not working. Thanks for your help. JN sub demo() Dim strlength As Integer Dim str As String str = "good morning" strlength = Len(Trim(str)) For i = 1 To strlength If Mid(str, i, strlength) = Chr(32) Then MsgBox "space" End If Next i End Sub -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Detecting the space character
One way:
Const str As String = "good morning" Dim nPos As Long nPos = InStr(str, " ") If nPos Then Msgbox "space at character " & nPos In article , "JN" wrote: Hi All, I am trying to detect the space character in a string but my code is not working. Thanks for your help. JN sub demo() Dim strlength As Integer Dim str As String str = "good morning" strlength = Len(Trim(str)) For i = 1 To strlength If Mid(str, i, strlength) = Chr(32) Then MsgBox "space" End If Next i End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Detecting the space character
Thanks for your replies...it is now working.
"JN" wrote in message ... Hi All, I am trying to detect the space character in a string but my code is not working. Thanks for your help. JN sub demo() Dim strlength As Integer Dim str As String str = "good morning" strlength = Len(Trim(str)) For i = 1 To strlength If Mid(str, i, strlength) = Chr(32) Then MsgBox "space" End If Next i End Sub |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Detecting the space character
Why not use Instr() ?
In any case, maybe you could try .... If Mid(str, i, 1) = Chr(32) Then .... Tim -- Tim Williams Palo Alto, CA "JN" wrote in message ... Hi All, I am trying to detect the space character in a string but my code is not working. Thanks for your help. JN sub demo() Dim strlength As Integer Dim str As String str = "good morning" strlength = Len(Trim(str)) For i = 1 To strlength If Mid(str, i, strlength) = Chr(32) Then MsgBox "space" End If Next i End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
is 3rd character in a cell a space? | Excel Worksheet Functions | |||
Can i give Space/some other character in between the cell? | Excel Worksheet Functions | |||
How do I replace a BEL Character of 7 with a space | Excel Discussion (Misc queries) | |||
NEED HELP-----Removing a space at the end of a string of character | Excel Discussion (Misc queries) | |||
How can I insert a space before the last character in a range of cells | Excel Programming |