How do you assign a Macro to an Excel command button?
Sam’s answer is right if you want to assign a macro to a TOOLBAR button. However, a command button is gotten from the Control Toolbox toolbar. To view it go to: View > Toolbars > Control Toolbox Select Command Button from the toolbar. Then place the new command button on the worksheet with the mouse, giving it the size you want. Then right-click the command button and choose View Code from the list. Then past your code into window that opens where the cursor is located. Once you have entered the code, go back to the Excel screen and and right click the button again and select Properties. Change the Caption to whatever you want the caption for the command button to say. Once you are done, close the properties window and click the drafting triangle on the Control Toolbox toolbar. The help text should say Exit Design Mode. You can close the window where you entered the code. When you click the command button, it should perform the operation you want if you wrote the macro correctly.