Macro - Jump to a cells Reference

rsulliva

Board Regular
Joined
Sep 13, 2007
Messages
131
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
What exactly is in the activecell (the original selected cell) as seen in the formula bar?
 
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,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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