Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to Find Specific Text in a Text String | Excel Discussion (Misc queries) | |||
Search, find or lookup defined text in text string | Excel Worksheet Functions | |||
can you find specific text in a string ignoring any other text | Excel Discussion (Misc queries) | |||
backwards find function to find character in a string of text | Excel Programming | |||
How to Find text in String? | Excel Programming |