Solved

Excel Macro - Lookup-Highlight

Posted on 2016-11-23
4
24 Views
Last Modified: 2016-11-24
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
0
Comment
Question by:Wass_QA
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 41900160
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
0
 

Author Comment

by:Wass_QA
ID: 41900366
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
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41900377
then try
Sub Macro1()
Range(Range("D2"), Range("D" & Rows.Count)).ClearContents
For Each c1 In Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
    For Each c In Range(Range("C2"), Range("C" & 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
            c.Offset(, 1) = IIf(c.Offset(, 1) = "", c1.Row, c.Offset(, 1) & ", " & c1.Row)
        End If
    Next
Next
End Sub

Open in new window

0
 

Author Closing Comment

by:Wass_QA
ID: 41900379
Awesome,
Thank you very much.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now