View Single Post
 
Old 07-05-2023, 03:34 AM
soroush.kalantari soroush.kalantari is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default How to go to Nth precedents of active cell?

I have written the following code to make excel go to nth direct precedents of a cell which are in the same sheet. (As far as I know, there is no way to write a code that does this job for precedents which are out of the sheet the active cell lies.) it failes to do its expected job. (see the excel attachment, when running the code for cell E1 and entering 2 in the input box appearing after running the code, it is expected to go to cell D4 but it goes to cell c2.

Sub gotopresedence()


Dim Rng As Range, RngPrecedents As Range

Dim i As Long, j As Long
Application.Goto Reference:=Selection
Set Rng = ActiveCell
Set RngPrecedents = Rng.DirectPrecedents
Application.Goto Reference:=RngPrecedents(InputBox("what presedence"))
End Sub
Attached Files
File Type: xlsm direct.precenedts.xlsm (15.7 KB, 4 views)
Reply With Quote