As a general rule of thumb, the code that goes in the module belonging to a worksheet is Eventcode that will automatically run when something occurs on the worksheet.
To find out what these events are, open a new workbook and right click a worksheet tab name and select View code. You will see 2 drop down boxes at the top of the white section of the VBA editor. The default values displayed in these will be (General) and
(Declarations). Click the left drop down and select Worksheet and a default sub and end sub name will appear. Now click on the right dropdown and see all of the events that can be used. If you select one of the events then the sub and end sub will appear in
the VBA editor and you can insert your code for the event.
If you add ActiveX controls to the worksheet then in the left dropdown you will see them listed also. If you select a control then a default sub and end sub will appear. The dropdown on the right will now display all of the events available for the ActiveX
control and if you select them then the sub and end sub for the event will appear in the
VBA editor.
Note: You must leave the Sub names as they were inserted. If you change them then the event will not be called.
All other Subs and User Defined Functions (UDF's) are normally placed in a general or standard module. To insert a standard module, in the VBA editor select Insert -> Module. You can have more than one standard module and you can rename them the default
of Module1, Module2 etc. (Select the module name on the left in the Project Explorer and press F4 to display the properties box.)
While most code can be written without changing the active worksheet and without selecting any ranges, if you do use code to change the Active worksheet when running event code and you then reference the active worksheet then you can get coding errors. If
it is necessary to change the Active sheet then it is best to place most of the coding in a sub in a standard module and only use the Event code to call that sub in the standard module.
Hope this helps.