Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
is 3rd character in a cell a space? Rick[_10_] Excel Worksheet Functions 5 December 21st 09 08:22 PM
Can i give Space/some other character in between the cell? sumit Excel Worksheet Functions 5 December 9th 08 08:34 AM
How do I replace a BEL Character of 7 with a space KBear Excel Discussion (Misc queries) 1 June 6th 06 03:56 PM
NEED HELP-----Removing a space at the end of a string of character FRS Excel Discussion (Misc queries) 7 April 13th 06 03:57 AM
How can I insert a space before the last character in a range of cells Jeff[_25_] Excel Programming 8 November 13th 03 08:45 PM


All times are GMT +1. The time now is 10:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"