Assume you are using Form controls, rather than ActiveX, and are trying to assign a macro.

Generally the button code would be stored in a standard code module.
But if you want to place the code in the sheet object then you can. You just need to assign the macro to the local routine.

Sheet1.Button2_Click