Solved

Excel Macro - Lookup-Highlight

Posted on 2016-11-23
4
47 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:W.E.B
  • 2
  • 2
4 Comments
 
LVL 49

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:W.E.B
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 49

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:W.E.B
ID: 41900379
Awesome,
Thank you very much.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

770 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