Link to home
Start Free TrialLog in
Avatar of W.E.B
W.E.B

asked on

Excel Macro - Lookup-Highlight

Hello,
Can you please help with a Sub ,
I need to lookup the Tracking in Column "C" inside cells in column "B".
if tracking found, highlight both tracking numbers. (Red Bold Font), and in column "D" enter Line Number Found in.

Your help is appreciate.
Sample attached.
-Sample.xlsx
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try
Sub macro()
For Each c In Range(Range("C2"), Range("C" & Rows.Count).End(xlUp))
    For Each c1 In Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
        If c1 Like "*" & c.Value & "*" Then
            pos = InStr(1, c1.Value, c.Value)
            Ln = Len(c.Value)
            With c
                .Font.Bold = True
                .Font.Color = vbRed
            End With
            With c1.Characters(pos, Ln)
                .Font.Bold = True
                .Font.Color = vbRed
            End With
            Range("D" & Rows.Count).End(xlUp).Offset(1) = c1.Row
            Exit For
        End If
    Next
Next
End Sub

Open in new window

Regards
Avatar of W.E.B

ASKER

Hello  Rgonzo1971,
Thank you very much.
it worked.
the only thing (which is my fault, I didn't add to the sample file), if the tracking number was found on multiple lines.
is it possible to show both lines it's found on.

Also,
when I run the sub more than once, the line numbers keep showing for empty cells.

Sample attached.
Thanks again.
-Sample.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of W.E.B

ASKER

Awesome,
Thank you very much.