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
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
Hi Lenny! To find a substring w/in a string, you use the InsStr 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.
Originally Posted by Lenny_821
Thanks T-容x
Lenny
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
>
>
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" <[email protected]> wrote
in message news:[email protected]...
>
> 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
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks