how to code the calculate command button in visual basic?

Answer :

On the Developer tab, click Button .
Click the worksheet location where you want the upper-left corner of the command button to appear. ...
In the Assign Macro dialog box, select New, which will open the Visual Basic Editor (VBE) to a pane with the following code: