Is it possible to link pages in two separate workbooks

taytools

New Member
Joined
Dec 7, 2017
Messages
8
Does anyone know if it is possible to link pages in multiple workbooks. I want to be able to click on a upc code in a cell and have it take me to the same upc code in a separate workbook. Does anyone know how to do this? Basically you would have to search by the upc code. I have done this in in different pages of an excel workbook, but never in two separate workbooks.

I have provided the code I used below. If anyone knows a way to modify it to work for two separate workbooks please let me know. Thanks!

Option Explicit

Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim Found As Range

Set Found = Worksheets("Sheet1").Cells.Find(what:=Target.Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
Cancel = True
Else
Cancel = False
Worksheets("Sheet1").Activate
Found.Select
End If

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You would just need to modify the Find function to reference the other workbook.
Code:
Set Found = Workbooks("SecondWorkbook.xlsx").Sheets(1).Cells.Find(What:=Target.Value, After:=Workbooks("SecondWorkbook.xlsx").Sheets(1).Cells(1, 1), _
    LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=True)

And, change the Activate to reference the workbook, as well.
Code:
Workbooks("SecondWorkbook.xlsx").Sheets(1).Found.Select
 
Last edited:
Upvote 0
Hi unfortunately I am still having trouble with the code. This is what I have been using. Can you see where I am running into trouble? Thanks so much!


Option Explicit

Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim Found As Range

Set Found = Workbooks("SecondWorkbook.xlsx"). Sheets(1) .Cells.Find(What:=Target.Value,
After: =Workbooks (“SecondWorkbook.xlsx”) . Sheets(1) .Cells (1, 1), _
Lookin: xlValues, LookAt: =xlPart, SearchOrder: =xlByRows,
SearchDirection: = xlPrevious, MatchCase: = True)
If Found Is Nothing Then
Cancel = True
Else
Cancel = False
Workbooks("SecondWorkbook.xlsx").Sheets(1) .Found.Select
Found.Select
End If

End Sub
 
Upvote 0
What trouble are you running into? Besides the missing underscores in the Find function, I'm not sure what errors you are running into.
 
Upvote 0
The macro will not run. I'm not sure what the problem is. Where should the underscores go? Would they keep the macro from running?
 
Upvote 0
Give this version a shot:
Code:
Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim Found As Range
    
    On Error Resume Next
    Set Found = Workbooks("SecondWorkbook.xlsx").Sheets(1).Cells.Find(What:=Target.Value, _
        After:=Workbooks(“SecondWorkbook.xlsx”).Sheets(1).Cells(1, 1), _
        LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, MatchCase:=True)
    On Error GoTo 0
        
    If Found Is Nothing Then
        Cancel = True
    Else
        Cancel = False
        Workbooks("SecondWorkbook.xlsx").Sheets(1).Found.Select
    End If
End Sub
 
Upvote 0
It says compile error variable not defined when I try to run the macro with that code. It also has the first row of code under option explicit highlighted. Any ideas?
Thanks!
 
Upvote 0
Try this one.
Code:
Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim Found As Range
    
    On Error Resume Next
    Set Found = Workbooks("SecondWorkbook.xlsx").Sheets(1).Cells.Find(What:=Target.Value, _
        After:=Workbooks(“SecondWorkbook.xlsx”).Sheets(1).Cells(1, 1), _
        LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, MatchCase:=True)
    On Error GoTo 0
        
    If Not Found Is Nothing Then
        Found.Select
    End If
End Sub
 
Upvote 0
Unfortunately the same problem is happening. The same pop up box comes up and it highlights the same things.
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,304
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top