View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default 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