Command button to move go to a range in a different wksht

emadams

New Member
Joined
Aug 8, 2007
Messages
14
Hi. I am trying to use the double click on a command button in sheet 1 to go to a specific cell in sheet 3.

I opened a new module and this the code I have (which doesn't work):

Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Application.Goto Worksheets("Sheet3").Range("H60"), Scroll:=True
End Sub

Can anyone tell me what is the problem here?

Thanks,
Emily
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You code works fine for me.

Did you turn off Design Mode?
Is the code in the Worksheet module?
 
Upvote 0
Yes, I turned off design mode.

I originally had it in the worksheet module and got an out of range error.

So, I copied and pasted the code to a new module (general), but I received a notice that my project code would be broken (or something along those lines)?

Not sure what that means.
 
Upvote 0
The code must be in the worksheet module for the page your button is on.

When in Design Mode, right click your command button, click View Code.
That is where the code should be.

You will get the error you spoke of when your project errors, just answer OK.
 
Upvote 0
This is where I originally had the code, but received an "out of range" error. I thought this was because I was trying to go to a different worksheet from the one that the code resided in.

I will try again.
 
Upvote 0
Okay, so I have finally solved my own problem here.

It was simple, actually, but being new to VB I didn't know.

I had "private" in front of sub and apparently that was keeping me from moving to a different sheet. As soon as took out "private", the code worked fine.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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