Home > Enterprise >  VBA - GoTo Command
VBA - GoTo Command

Time:06-18

I'm trying to use the GoTo command in Excel to GoTo a variable cell value, but I'm struggle how to get the cell address into VBA, any thoughts?

Within my Excel document I have defined the name of a cell (i.e. created a range), lets call it "x" for ease, that contains the cell address, for example $B$3. However it's important to note the value within the range changes as I modify the document, it's not static.

I have tried
Application.GoTo Range("x")
and
Application.GoTo Range("x").value
but neither of these seem to work.

Can I achieve what I need to using GoTo or should I be using a different command entirely?

The context should it help is that I have created a task list tab and when selecting that tab I want to GoTo the latest actionable task. I understand what this is, I just can't reach it!

CodePudding user response:

You set a string variable to the cell location, and then use GoTo with Reference - see example below:

Dim myCell As String
myCell = Range("A3").Value
Application.GoTo Reference:=Range(myCell)

CodePudding user response:

The GoTo statement is used for branching in the code only. It doesn't interact with the cells at all. See the Microsoft docs here.

As findwindow says in the comments, you need to use the Range.select method. MSDN here

  • Related