Run Subroutine located in Sheet1 from a command button in a form?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
417
Office Version
  1. 2007
Platform
  1. Windows
Hello,
I’m trying to run a subroutine(s) from a command button on a form.

Originally I was running the Subs directly from buttons on the worksheet. However, I am getting too many buttons so I decided to create a separate form with all the buttons. Then there is only one button on the worksheet that opens my form (frmControlCenter) with all the other buttons. Most of these are working fine. However, there are a couple that return errors. The one Sub in particular I am working on is called cmdRESET_Click() where I am attempting to run to previous worksheet button's sub called cmdClearALL_Click.

Here is my code on the form that I am attempting to run cmdClearALL_Click():
Not sure if it matters but I should note, Sheet1 is named "Amoritze".
VBA Code:
Private Sub cmdRESET_Click()
   Application.Run "Sheet1.ClearALL_Click"
End Sub

Here is the error and highlighted coding problem:
1722350693318.png


1722350711099.png


Any suggestions would be appreciated.

Thanks for viewing,
Steve K.
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi Steve. I suggest moving your sheet subs to modules and making them public. They would no longer be command button codes (ie. Public Sub ClearAll). You can then simply "Call ClearALL" for example to run the sub from the form. HTH. Dave
 
Upvote 0
Solution
Hi Steve. I suggest moving your sheet subs to modules and making them public. They would no longer be command button codes (ie. Public Sub ClearAll). You can then simply "Call ClearALL" for example to run the sub from the form. HTH. Dave
Thank you Dave, that helped. I still am having a few minor issues but I think I'm going in the right direction - I'll keep at it. Any other problems, I'm sure I'll be back.

Just a question here - based on your suggestion, I assume I should just move all the code in a Module or two and make all the Subs Public?
I think you can tell I really don't know much about this - but I try. . .

Thanks again,
Steve K.
 
Upvote 0
You are welcome. As fa as moving all your subs to a module and making them public, it depends on how you use the subs. Public subs in modules are available to the entire project ie. they can be called from sheet code or form code. Form code is only available to the form. Thanks for posting your outcome. Dave
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
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