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 Text within Text String


Hi All,

I've got bit of a puzzle here. I've got 2 text strings for example A
"Model A" and B = "A". Now I want to, in VBA, find Text B within Tex
A. How do I do that?

Thanks:)

Lenn

--
Lenny_82
-----------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...fo&userid=1517
View this thread: http://www.excelforum.com/showthread.php?threadid=40036

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Text within Text String


Hi Lenny! To find a substring w/in a string, you use the InsSt
function:

InStr([start, ]string1, string2[, compare])

InStr(1, A, B)

It returns the position of string2 in string1 if found.

See VBA help for more details.

Lenny_821 Wrote:
Hi All,

I've got bit of a puzzle here. I've got 2 text strings for example A
"Model A" and B = "A". Now I want to, in VBA, find Text B within Tex
A. How do I do that?

Thanks:)

Lenn


--
T-®e
-----------------------------------------------------------------------
T-®ex's Profile: http://www.excelforum.com/member.php...fo&userid=2657
View this thread: http://www.excelforum.com/showthread.php?threadid=40036

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find Text within Text String

In your example InStr(A,B) gives 7,
because "A" is the seventh character of "Model A" .
Regards,
Stefi


€˛Lenny_821€¯ ezt Ć*rta:


Hi All,

I've got bit of a puzzle here. I've got 2 text strings for example A =
"Model A" and B = "A". Now I want to, in VBA, find Text B within Text
A. How do I do that?

Thanks:)

Lenny


--
Lenny_821
------------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...o&userid=15179
View this thread: http://www.excelforum.com/showthread...hreadid=400363


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

Hi Lenny_821,

Look at the InStr function in VBA help.

Assume:
A1: Model A
B1: A

Sub Tester01()
Dim str1 As String, str2 As String

str1 = Range("A1").Value
str2 = Range("B1").Value

If InStr(1, str1, str2, vbTextCompare) 0 Then
'substring found, do something, e.g.
MsgBox """" & str2 & """ found in " & """" & str1 & """"
'found in " & "" & str1 & """"

Else
'substring not found, do something else, e.g.
MsgBox """" & str2 & """ not found in " & """" & str1 & """"
End If
End Sub


---
Regards,
Norman



"Lenny_821" wrote
in message ...

Hi All,

I've got bit of a puzzle here. I've got 2 text strings for example A =
"Model A" and B = "A". Now I want to, in VBA, find Text B within Text
A. How do I do that?

Thanks:)

Lenny


--
Lenny_821
------------------------------------------------------------------------
Lenny_821's Profile:
http://www.excelforum.com/member.php...o&userid=15179
View this thread: http://www.excelforum.com/showthread...hreadid=400363



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find Text within Text String


Thanks T-®ex:):)

Lenny


--
Lenny_821
------------------------------------------------------------------------
Lenny_821's Profile: http://www.excelforum.com/member.php...o&userid=15179
View this thread: http://www.excelforum.com/showthread...hreadid=400363

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
How to Find Specific Text in a Text String Confused_in_Houston[_2_] Excel Discussion (Misc queries) 2 January 26th 09 08:17 PM
Search, find or lookup defined text in text string zzxxcc Excel Worksheet Functions 9 September 6th 07 09:37 PM
can you find specific text in a string ignoring any other text chriscp Excel Discussion (Misc queries) 1 September 18th 05 09:54 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM
How to Find text in String? Milind Excel Programming 0 September 2nd 03 10:26 PM


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