Macro - Jump to a cells Reference

rsulliva

Board Regular
Joined
Sep 13, 2007
Messages
133
Office Version
  1. 365
Platform
  1. Windows
I would like the following code to create a duplicate window, tile these windows vertically, follow the reference from the originally selected cell, then select this cell's referenced cell in the second window. Everything seems to be working correctly until the last line of code where it will not select the second window and the corresponding cell the original cell is referencing. Any suggestions? Thanks

VBA Code:
Sub SplitWindowFollowCellRef()

Dim OriginalActiveCell As Range
Set OriginalActiveCell = ActiveCell

'Create a new duplicate window and tile these two windows vertically
ActiveWindow.NewWindow
Windows.Arrange ArrangeStyle:=xlVertical

'Refer to the original active cell and copy its formula reference and go to this cell in the second window
MyRef = OriginalActiveCell.Formula
Application.Goto Reference:=MyRef

End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
VBA Code:
    'Refer to the original active cell and goto the cell referenced in its formula in the second window
    Application.Goto ActiveSheet.Range(OriginalActiveCell.Precedents.Address)
 
Upvote 0
I tried this code but it keeps telling me that there is a "run time error 1004 - no cells were found". Also, note that the original selected cell is on Sheet 1 and the referenced cell is on Sheet 2. Same workbook though.
 
Upvote 0
Hey AlphaFrog,

The exact link in the cell in the formula bar is ='Files to be Completed'!B19 but note the following . This macro should be able to run on any cell within any sheet within any workbook and go to the link/reference within that cell. If the formula for whatever reason has more than one link, it should only go to the first one.

Thank you.
 
Upvote 0
This is a bit of a kludge, but it seems to work... for me.

VBA Code:
Sub SplitWindowFollowCellRef()

Dim OriginalActiveCell As Range, FirstPrecedent As Range
Set OriginalActiveCell = ActiveCell
ActiveCell.ShowPrecedents
ActiveCell.NavigateArrow True, 1
Set FirstPrecedent = ActiveCell
Application.Goto OriginalActiveCell
OriginalActiveCell.ShowPrecedents Remove:=True

'Create a new duplicate window and tile these two windows vertically
ActiveWindow.NewWindow
Windows.Arrange ArrangeStyle:=xlVertical

'In the 2nd window, goto the 1st precedent of the original activecell's formula
Sheets(FirstPrecedent.Parent.Name).Select
Range(FirstPrecedent.Address).Activate

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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