ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   search for string within a string (https://www.excelbanter.com/excel-programming/342438-search-string-within-string.html)

cretesupplies

search for string within a string
 
i have to columns in an Excel worksheet.
Column A has codes(text),one in every cell.
Column B has description(text)one in every cell.
Codes from column A exist somewhere in column B and some not.

How do i match the cells from column A to the cells in column B that under
the condition that a cell in column B contains the string from column A

Thank u in advance

Tom Ogilvy

search for string within a string
 
this uses the find command and places the address of the cell in column A in
column C next to the cell in Column B that contains the target.

Hopefully you can adapt it to your needs.

Sub FindStrings()
Dim cell As Range, rng As Range
Dim sAddr As String
For Each cell In Range("A1:A100")
Set rng = Columns(2).Find(What:=cell.Value, _
After:=Range("B65536"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not rng Is Nothing Then
sAddr = rng.Address
Do
rng.Offset(0, 1).Value = rng.Offset(0, 1).Value _
& cell.Address & ","
Set rng = Columns(2).FindNext(rng)
Loop While rng.Address < sAddr
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"cretesupplies" wrote in message
...
i have to columns in an Excel worksheet.
Column A has codes(text),one in every cell.
Column B has description(text)one in every cell.
Codes from column A exist somewhere in column B and some not.

How do i match the cells from column A to the cells in column B that under
the condition that a cell in column B contains the string from column A

Thank u in advance




Dave Peterson

search for string within a string
 
You could use a helper column (column C) of cells with formulas like:

=INDEX(B:B,MATCH("*"&A1&"*",B:B,0))
and drag down.

If there is no match, you'll see an #n/a error.

If you're just looking for the row that has the match:
=MATCH("*"&A1&"*",B:B,0)





cretesupplies wrote:

i have to columns in an Excel worksheet.
Column A has codes(text),one in every cell.
Column B has description(text)one in every cell.
Codes from column A exist somewhere in column B and some not.

How do i match the cells from column A to the cells in column B that under
the condition that a cell in column B contains the string from column A

Thank u in advance


--

Dave Peterson


All times are GMT +1. The time now is 11:32 AM.

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