Solved

Excel Macro - Lookup-Highlight

Posted on 2016-11-23
4
66 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

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 52

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

636 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