Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2008

Tip: Looking for answers? Try searching our database.

Using Excel VBA - Finding Characters in Strings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Noitide@gmail.com - 20 Mar 2008 07:56 GMT
Hello,

    I am trying to figure out whether or not a string has a space in
its contents. I am using the following code.
(AppWSF is set equal to Application.WorksheetFunction)

If IsError(AppWSF.Find(" ", Given_Data.Value, 1)) = False Then
       HasSpace = True
       SpaceLoc = AppWSF.Find(" ", Given_Data.Value, 1)
End If

It works fine if there is a space in the string; however, it has an
error and quits running if there is no space in the string. Any help
would be appreciated!

Thanks,
bart.strubbe@scarlet.be - 20 Mar 2008 08:59 GMT
> Hello,
>
[quoted text clipped - 12 lines]
>
> Thanks,

without trying it myself
Replaced=replace(Given_data.value," ","")
if Replaced=Given_data.value then
  HasSpace=true
else
 HasSpace=false
endif
greetings
bart
bart.strubbe@scarlet.be - 20 Mar 2008 09:02 GMT
> > Hello,
>
[quoted text clipped - 24 lines]
>
> - Show quoted text -

sorry something wrong
if Replaced=Given_data.value then
must be
if Replaced<>Given_data.value then

bart
Dana DeLouis - 20 Mar 2008 12:08 GMT
> I am trying to figure out whether or not
> a string has a space in its contents.

Would this work?

Function HasSpaceQ(S As String) As Boolean
 HasSpaceQ = S Like "* *"
End Function

Signature

HTH   :>)
Dana DeLouis

> Hello,
>
[quoted text clipped - 12 lines]
>
> Thanks,
Dave Peterson - 20 Mar 2008 12:25 GMT
You could use VBA's equivalent of =find().

if instr(1, given_data.value, " ", vbtextcompare) > 0 then
 'has a space
else
 'doesn't have a space
end if

> Hello,
>
[quoted text clipped - 12 lines]
>
> Thanks,

Signature

Dave Peterson


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.