Solved

Compare Lists on Two Worksheets Then Flag and Link Matching Location

Posted on 2012-03-29
6
256 Views
Last Modified: 2012-03-31
Need to compare all the Point Name values in sheet LIST-A with Point Name values in sheet LIST-B.
If the Name in LIST-A has a unique match (should be unique) anywhere in LIST-B then Flag LIST-A sheet Column B "IN ICS" with Y else N  and then provide a hyper-link (or cell reference if H-Link not possible) to the matching cell location in LIST-B on LIST-A in Column C "LINK".

Both lists will have variable lengths going forward.

Reference Attached Workbook.

Thanks!
20120329-EE-Compare-Lists.xlsx
0
Comment
Question by:BrianEsser
[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
  • 4
  • 2
6 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 37785212
Put this in column B in List-A and copy down:

[B2]=IF(COUNTIF('LIST-B'!$B$2:$B$34575,$A2)=1,"Y","N")

Put this in column C in List-A and copy down:
[C2]=IF($B2="Y",HYPERLINK("#" &ADDRESS(MATCH($A2,'LIST-B'!$B$2:$B$34575,0),2,,,"List-B"),"Link to LIST-B"),"Cell reference to link in LIST-B not possible")

Its a big lookup, so it will take a moment to calculate.  You can turn calculations to manual and then hit F9 when you want an update.  You can also keep the first row of formulas and then convert the rest to values by selecting the rest, copy/pastespecial values, and it will be fast, but you'll have to update the formulas again to update the link.

The only other alternative is to write a vba macro that does this step for you in a button.

Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37785250
I've written a vba script to do this for the entire sheet, or just rows you select, so you can update only a few rows and it runs significantly faster when just updating a few rows:

Option Explicit

Sub setupMatchAndHyperlink()
Dim wksA As Worksheet
Dim wksB As Worksheet
Dim firstRowA As Long
Dim lastRowA As Long
Dim lastRowB As Long
Dim rng As Range
Dim r As Range
Dim xCalc As Long
Dim xMsg As Long

    xCalc = Application.Calculation
    Application.Calculation = xlCalculationManual
    
    Set wksA = ThisWorkbook.Sheets("LIST-A")
    Set wksB = ThisWorkbook.Sheets("LIST-B")
    
    xMsg = MsgBox("Referesh entire sheet, or just selected rows?", vbYesNo, "YES for Entire Sheet, NO for selected rows")

    lastRowB = wksB.Range("A" & wksB.Rows.Count).End(xlUp).Row
    
    If xMsg = vbYes Then
        firstRowA = 2
        lastRowA = wksA.Cells(wksA.Rows.Count, 1).End(xlUp).Row
    Else
        firstRowA = Selection.Cells(1, 1).Row
        lastRowA = Selection.Offset(Selection.Rows.Count - 1, 0).Resize(1, 1).Row
    End If
    
    Set rng = wksA.Range("B" & firstRowA, "B" & lastRowA)
    
    rng.Formula = "=IF(COUNTIF('LIST-B'!$B$" & firstRowA & ":$B$" & lastRowB & ",$A" & firstRowA & ")=1,""Y"",""N"")"
    
    rng.Offset(, 1).Formula = "=IF($B" & firstRowA & "=""Y"",HYPERLINK(""#"" & ADDRESS(MATCH($A" & firstRowA & ",'LIST-B'!$B$" & firstRowA & ":$B$" & lastRowB & ",0),2,,,""List-B""),""Link to LIST-B""),""Cell reference to link in LIST-B not possible"")"
    
    rng.Resize(rng.Rows.Count, 1).Value = rng.Resize(rng.Rows.Count, 1).Value
    
    'Application.Calculate
    Application.Calculation = xCalc
End Sub

Open in new window


See attached.

Dave
20120329-EE-Compare-Lists-r1.xlsm
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37785319
A slight error - the formula in column C should be:

[C2]=IF($B2="Y",HYPERLINK("#" & ADDRESS(MATCH($A2,'LIST-B'!$B$1:$B$34575,0),2,,,"List-B"),"Link to LIST-B"),"Cell reference to link in LIST-B not possible")

Attached, please find the r1 version of the VBA enabled workbook with this correction.

Also, I'm rewriting the VBA script in hopes of speeding up the process.  Give me a moment.

Dave
20120329-EE-Compare-Lists-r1.xlsm
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 37785385
This version takes a bit to run because its creating an embedded hyperlink on every row with unique link, but you are not encumbered with the HYPERLINK formula updating every time the workbook calculates (assuming you're doing other stuff with the workbook).

Let me know which version you prefer and if you have any issues.

Option Explicit

Sub setupMatchAndHyperlink()
Dim wksA As Worksheet
Dim wksB As Worksheet
Dim firstRowA As Long
Dim lastRowA As Long
Dim lastRowB As Long
Dim rng As Range
Dim r As Range
Dim xCalc As Long
Dim xMsg As Long
Dim vLink As Variant

    Application.ScreenUpdating = False
    
    xCalc = Application.Calculation
    Application.Calculation = xlCalculationManual
    
    Set wksA = ThisWorkbook.Sheets("LIST-A")
    Set wksB = ThisWorkbook.Sheets("LIST-B")
    
    xMsg = MsgBox("Referesh entire sheet, or just selected rows?", vbYesNo, "YES for Entire Sheet, NO for selected rows")

    lastRowB = wksB.Range("A" & wksB.Rows.Count).End(xlUp).Row
    
    If xMsg = vbYes Then
        firstRowA = 2
        lastRowA = wksA.Cells(wksA.Rows.Count, 1).End(xlUp).Row
    Else
        firstRowA = Selection.Cells(1, 1).Row
        lastRowA = Selection.Offset(Selection.Rows.Count - 1, 0).Resize(1, 1).Row
    End If
    
    Set rng = wksA.Range("B" & firstRowA, "B" & lastRowA)

    For Each r In rng
        r.Formula = "=IF(COUNTIF('LIST-B'!$B$2:$B$" & lastRowB & ",$A" & r.Row & ")=1,""Y"",""N"")"
        If r.Value = "Y" Then
            r.Offset(, 1).Clear
            vLink = Evaluate("=ADDRESS(MATCH($A$" & r.Row & ",'LIST-B'!$B$1:$B" & lastRowB & ",0),2,,,""List-B"")")
            r.Offset(, 1).Hyperlinks.Add anchor:=r.Offset(, 1), Address:="", SubAddress:=vLink, TextToDisplay:="Link to LIST-B"
        Else
            r.Offset(, 1).Value = "Cell reference to link in LIST-B not possible"
        End If
        r.Value = r.Value
    Next r
    
    Application.ScreenUpdating = True
    Application.Calculation = xCalc
End Sub

Open in new window


See attached.

Dave
20120329-EE-Compare-Lists-r2.xlsm
0
 

Author Comment

by:BrianEsser
ID: 37789963
Sorry for the delay getting back to my question and your responses - I'm going to go over the responses now... Thanks!
0
 

Author Closing Comment

by:BrianEsser
ID: 37789981
Dave,

This is certainly an improvement over the previous version you offered and it was prescient of you to anticipate I would be using this solution as a component of a larger Workbook where the Hyperlink formula recalcs would have been cumbersome. Where's the extra credit check box on this form - you deserve the extra mile award.

I look forward to reverse engineering your method to incorporate into my production Workbook and augmenting my ongoing education for applying Excel VBA automation. If I encounter any issues with the code/implementation I'll post a new question. Thank you for such an elegant solution to add to my Knowledge Base.

Brian
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

734 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