Code placement

MrByte

Board Regular
Joined
Feb 9, 2007
Messages
167
Office Version
  1. 365
When is it a good time to place code in a 'Sheet'? Here is the situation, I currently have code in a 'Sheet4 (Sum)' and when I run it I get an error 400. Now If I put the code in a module then I do not get the error.

So back to my question when is it good practice to place code in a 'Sheet'?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
It's hard to tell why you're getting an error without seeing your code.

Generally speaking though, Worksheet level events (Change, ActiveX code, etc.) go in the sheet module and global code goes in general modules.

HTH,

Smitty
 
Upvote 0
you might want to put a code 'in a sheet" when you want the code to be triggered when:

Activate the sheet
Before double click on the sheet
Before Right click on the sheet
Changing the sheet
Changing the selection in the sheet etc

macros are good when you want to run the code manually
 
Upvote 0
Okay with those two answers in mind, I thank you. So let me further explain then on the worksheet I used the form command button to create a button on the worksheet to "activate" the code. Should I use the command command button to create a button on the worksheet?
 
Upvote 0
Forms and ActiveX controls have different uses, although some people prefer one over the other.

I look at it this way, if you have a macro you want to run on all sheets you can assign it to a Forms button and copy the button to each sheet and the assigned code will follow it to each sheet.

ActiveX controls are hardcoded on each sheet and are Private to each sheet, although you can "call" general subs from them.

So if you're referring to a general sub, I'd just use a Forms button.

Smitty
 
Upvote 0
Thanks ps & id I believe I figured it out. It does help to create a command button with the command toolbar instead of the forms toolbar. One is different from the other. Is this where one is an Active X control? ooops ps you answered my question before I asked it.
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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