#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default Instr

Hi,

How would I catch the error if the string does not have a space in it and
save the value as it is in that case?

For iCtr = 2 To OldLusedrow
OldString = ws.Range("B" & iCtr).Value
ws.Range("A" & iCtr).Value = Left(OldString, InStr(OldString, "
") - 1)
Next

--
Thanks for your help.
Karen53
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Instr

Dim SpacePos as long

For iCtr = 2 To OldLusedrow
OldString = ws.Range("B" & iCtr).Value
spacepos = instr(1, oldstring, " ", vbtextcompare)
if spacepos = 0 then
'no spaces, so no changes
else
ws.range("a" & ictr).value = left(oldstring, spacepos-1)
end if
next ictr

Maybe???????

Karen53 wrote:

Hi,

How would I catch the error if the string does not have a space in it and
save the value as it is in that case?

For iCtr = 2 To OldLusedrow
OldString = ws.Range("B" & iCtr).Value
ws.Range("A" & iCtr).Value = Left(OldString, InStr(OldString, "
") - 1)
Next

--
Thanks for your help.
Karen53


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 333
Default Instr

Never Mind. I got it.

Thanks
--
Thanks for your help.
Karen53


"Karen53" wrote:

Hi,

How would I catch the error if the string does not have a space in it and
save the value as it is in that case?

For iCtr = 2 To OldLusedrow
OldString = ws.Range("B" & iCtr).Value
ws.Range("A" & iCtr).Value = Left(OldString, InStr(OldString, "
") - 1)
Next

--
Thanks for your help.
Karen53

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default Instr

Hi Karen

Dim test as Integer
Dim Newstring as String

For iCtr = 2 To OldLusedrow
OldString = ws.Range("B" & iCtr).Value
Test=Instr(OldString," ")
If Test = 0 then
Newstring = Oldstring
Else
Newstring = Left(Oldstring, test)
End If
ws.Range("A" & iCtr).Value = NewString
Next


--
Regards
Roger Govier

"Karen53" wrote in message
...
Hi,

How would I catch the error if the string does not have a space in it and
save the value as it is in that case?

For iCtr = 2 To OldLusedrow
OldString = ws.Range("B" & iCtr).Value
ws.Range("A" & iCtr).Value = Left(OldString, InStr(OldString, "
") - 1)
Next

--
Thanks for your help.
Karen53


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
Instr ranswert Excel Programming 2 February 8th 08 12:55 PM
instr() ? mark kubicki Excel Programming 3 November 16th 06 05:07 PM
InStr Harley Excel Programming 3 August 9th 05 08:55 PM
InStr FGM Excel Programming 3 July 14th 05 08:47 PM
InStr and ADO Al Excel Programming 2 June 17th 04 04:22 PM


All times are GMT +1. The time now is 10:54 AM.

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

About Us

"It's about Microsoft Excel"