VBA Application.Goto Macro

Diaxus

Board Regular
Joined
Mar 14, 2017
Messages
55
I have researched this for several hours and attempted every option and fix I could find or think of, and having failed I figure it's time to ask about my specific need.

I have a formula in cell D2 of sheet7("Missions") that first chooses a table from six table options on the same worksheet based on input in cell C2. Next, the formula looks for a line of text based on what is written in cell C3. Finally, I used CONCATENATE to insert "C" before the numeric value that the formula will find, giving me a variable cell reference. The exact formula in cell D2 is:

Code:
=CONCATENATE("C",IF(Table76[@[Search Input]]="Lord Harrow",MATCH(C3,Table75[Lord Harrow],0),0))

That much is simply to fill you in on how I am attempting to fulfill my goal. The problem is this. I have created an ActiveX button on the same worksheet (which feeds on VBA code in sheet7) that is intended to go to the cell the above formula depicts. I am trying to use the Application.Goto method. Below is what I have now:

Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim L As String
Dim G As Range
Set L = Range("D2").Value
Set G = Range(L)
Application.Goto G, True
End Sub

Naturally, Option Explicit is separated, in case anyone is wondering. I have tried various other codes, such as:

Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim r As Integer
Set r = Range("D2").Value
Application.Goto r, True
End Sub

and

Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim r As Range
Set r = Range("D2").Value
Application.Goto r, True
End Sub

among many others.

The current error is "Compile Error: Object Required" which highlights the "Set" line. I don't understand, because I thought the object was already set by the "Dim" command.

Any help would be greatly appreciated, as by this point I'm pretty sure I've received at least half of all the possible error codes. Thank you for your time.
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I misspoke. The error highlights the Sub routine itself, and the "L=" in the first "Set" line is selected in blue.
 
Upvote 0
if L in D2 is 250 then how does
Set G = Range(L) work as Set G = Range(250) which wouldn't be a range the nearest I can think of is Rows(L:L)
 
Upvote 0
What happens if you remove the Set in front of L?
i.e.
Code:
Private Sub CommandButton1_Click()
Dim L As String
Dim G As Range
Set L = Range("D2").Value
Set G = Range(L)
Application.Goto G, True
End Sub

becomes

Code:
Private Sub CommandButton1_Click()
Dim L As String
Dim G As Range
L = Range("D2").Value
Set G = Range(L)
Application.Goto G, True
End Sub
 
Upvote 0
The idea at this point was to make the macro interpret the results of D2 as string, named "L", and then turn L into a range, "G". I'm not sure that is a good idea, or that it is what is actually happening, but the error seems to be almost from the outset, with "Set L".
 
Upvote 0
L is a String not a range and so you don't use Set, Set only applies to objects.
 
Last edited:
Upvote 0
Hence the "Object Required" error... Thank you, I'll remember that! And thanks to you as well Mole for your time!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,180
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