macro - range name to reference contents of another cell

fulmar57

New Member
Joined
Mar 10, 2019
Messages
8
Hi

In this macro line, Application.Goto Reference:="rangename"

I need the "rangename" to be given by the contents of another cell eg A1, because it will change

I'm sure it's simple - but not to me. Thanks for your help.

M
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
For named ranges I find it is best to store an additional sheet within the workbook. 3 columns (name of range, sheet name, description)

That way you can find the exact range and sheet. Something like below

Code:
Dim NamedRange As String, WorksheetName as String
Dim Fnd As Range, Rng As Range

   NamedRange = Sheets(xxx).Cells(1,1).Value
   Set Fnd = Sheets("NamedRangeInfo").Range("A:A").Find(NamedRange, , , xlWhole, , , False, , False)

   If Fnd Is Nothing Then
     MsgBox "Unable to Find Named Range in the information sheet", vbinformation, "Error..."
     Exit Sub
   Else
     WorksheetName = Fnd.Offset(0,1).Value
   End If

   Set Rng = ThisWorkbook.Sheets(WorksheetName).Range(NamedRange)

   Application.Goto Reference:= Rng
  
   Set Rng = Nothing
   Set Fnd = Nothing
 
Upvote 0
Try:
Code:
 Application.Goto Reference:=Range("A1").Value
 
Upvote 0
Deleted as over complicating it, the previous post from Akuini works fine for me.
 
Last edited:
Upvote 0
Actually I have another related question...
That solution worked fine where the range name contained the location as a range name. But I also want to make the macro select a cell (ie go to that cell), where the cell address (eg C45) is given by the content of another cell. The content varies.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,795
Members
449,048
Latest member
greyangel23

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