Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Character Position in String


Hi there,

I am writing some code in Excel VBA, and I need to find the position of
a colon in a string variable. I thought I would be able to use the
'find' function to return the position value as I would on a normal
worksheet. However, VBA doesn't seem to recognise the function ("Sub or
Function not Defined"). I have also checked the help files and there
seems to be no mention of it. Could somebody please advise me on an
alternative.

Many thanks,

Dave


--
SportsDave
------------------------------------------------------------------------
SportsDave's Profile: http://www.excelforum.com/member.php...o&userid=34641
View this thread: http://www.excelforum.com/showthread...hreadid=544078

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Find Character Position in String

Hi SportsDave,

Try something like:

'=============
Public Sub Tester()
Dim sStr As String
Dim pos As Long

sStr = "test;String"

pos = InStr(1, sStr, ";", vbTextCompare)

MsgBox pos
End Sub
'<<=============


---
Regards,
Norman



"SportsDave" wrote
in message ...

Hi there,

I am writing some code in Excel VBA, and I need to find the position of
a colon in a string variable. I thought I would be able to use the
'find' function to return the position value as I would on a normal
worksheet. However, VBA doesn't seem to recognise the function ("Sub or
Function not Defined"). I have also checked the help files and there
seems to be no mention of it. Could somebody please advise me on an
alternative.

Many thanks,

Dave


--
SportsDave
------------------------------------------------------------------------
SportsDave's Profile:
http://www.excelforum.com/member.php...o&userid=34641
View this thread: http://www.excelforum.com/showthread...hreadid=544078



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Find Character Position in String

Hi SportsDave,

pos = InStr(1, sStr, ";", vbTextCompare)



For your purposes, repalce the shown semicolon string with a colon!


---
Regards,
Norman


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Find Character Position in String

if the string is typed in A1 then something like the below will do it:
hopethis helps
J

Sub FindColon()

Dim SearchString, SearchChar, MyPos

SearchString = Cells(1, 1) 'range("A1") contains the string
SearchChar = ":" 'Search for ":".

MyPos = InStr(1, SearchString, SearchChar, vbTextCompare)

MsgBox "The colon was character: " & MyPos

End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find Character Position in String

Dim s as String, iloc as Long
s = "Some string with a : contained within"
iloc = Instr(1,s,":",vbTextCompare)

--
Regards,
Tom Ogilvy


"SportsDave" wrote
in message ...

Hi there,

I am writing some code in Excel VBA, and I need to find the position of
a colon in a string variable. I thought I would be able to use the
'find' function to return the position value as I would on a normal
worksheet. However, VBA doesn't seem to recognise the function ("Sub or
Function not Defined"). I have also checked the help files and there
seems to be no mention of it. Could somebody please advise me on an
alternative.

Many thanks,

Dave


--
SportsDave
------------------------------------------------------------------------
SportsDave's Profile:

http://www.excelforum.com/member.php...o&userid=34641
View this thread: http://www.excelforum.com/showthread...hreadid=544078



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Character Position in String


Thanks a lot everyone. Help very much appreciated.

Dav

--
SportsDav
-----------------------------------------------------------------------
SportsDave's Profile: http://www.excelforum.com/member.php...fo&userid=3464
View this thread: http://www.excelforum.com/showthread.php?threadid=54407

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
return a character at a certain position in a string of text Miranda Excel Worksheet Functions 3 May 8th 23 11:46 AM
Find position of first non-matching character Greg Lovern Excel Worksheet Functions 18 June 1st 08 01:52 AM
Function to return Character Position of Xth character within a string Andibevan[_2_] Excel Programming 4 June 9th 05 03:24 PM
function for finding position of numeric character in a string Paul Excel Programming 5 February 6th 05 12:19 AM
How find character position # in string from right end? Or how get range row num Ian Elliott[_3_] Excel Programming 1 December 17th 03 03:56 PM


All times are GMT +1. The time now is 02:05 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"