Compare two columns using loop.

P

Peter Gasparik

Hi,

Could you please help my create a loop which will compare each value in
column A one by one with whole column B whether it contain value in column B
and if yes the it picks up value from column C and put it to column D.

Please see example.

Please note the search must be able to find value which is included in
string of the text like Peter must be finding in PeterIsGood.

Example:
A B C D
Peter PeterIsGood T1 T1
Martin Test T2 N/A
John Cool T3 N/A
Oscar PeterIsGood T4 T1
Tom Tomknowall T5 T5
Joseph Summer T6 N/A

Many thanks,

Peter.
 
O

Otto Moehrbach

Something like this perhaps. I assumed your headers are in row 1 and your
data starts in row 2. HTH Otto
Sub CompareCol()
Dim rColA As Range, rColB As Range, i As Range
Set rColA = Range("A2", Range("A" & Rows.Count).End(xlUp))
Set rColB = Range("B2", Range("B" & Rows.Count).End(xlUp))
For Each i In rColA
If Not rColB.Find(What:=i.Value) Is Nothing Then
i.Offset(, 3) = i.Offset(, 2)
End If
Next i
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top