The easiest way I know how to do it is write your macro first. Next, insert your control button and then double click on it (that should open the VBA editor window). Next, copy the macro you wrote (excluding the "Sub" and "end" lines) and paste it in the command button sub proceedure. Then just exit the design mode (in excel) and you should be able to execute the macro by clicking you button. Alternately (as long as you know the name of your cammand button), you can just re-name your sub proceedure from:
Sub MyMarco() to Sub CommandButton1_Click()
but this will only work if the command button is named "CommandButton1". If you get stuck, search the help.
When I create a button, a box pops up asking if I want to assign a macro. Or right-click an existing button and select 'assign macro.' Then assign existing code or create new code with the name suggested.