ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find Text within Text String (https://www.excelbanter.com/excel-programming/338695-find-text-within-text-string.html)

Lenny_821[_18_]

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


T-®ex[_43_]

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


Stefi

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



Norman Jones

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




Lenny_821[_19_]

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



All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com