Excel VBA create a Button

In your interaction with your user, you will need to have various means to exchange with him. The Button is one very useful. Here is how to do it.

Now we are going to insert a Button around the cell A1. For this press the Insert Tab in the DEVELOPER RIBBON.

insert Button

Then press the top left item, which is a button.

The cursor will change into a cross.

create button

Draw a rectangle around the cell A1 area.

As soon as you release the mouse button, the following window will open.



 

macro1

Change the name to one that suits you.

Button in VBA

Once you press OK, the Button will appear where you create it.

Button in VBA



You will see that you need to add code to this button, because pressing on it, will not do anything.

Here is how to assign code to it.

Right click on the button and press the Assign Macro command.

Button in VBA

If you never had a macro then the menu will be empty like here and you will be given two options. One is record a new macro or Edit a macro.

The new macro button will open the editor and you can write your code (see the advanced VBA tutorial) or you can record it and to see how this is done, we have shown it in a different page where we create two buttons to jump from one page to another. Have a look at this page here.

Button in VBA

If you have some already like here with Macro1, it will look like this. Only the Edit Button will be available.

Select the macro you want to assign the button to and that's it. You have linked the button with the macro.

If you want to Edit it, it will open the VBA editor and there you can change the code to your desire.

Button in VBA

 

Congratulation, you made it until the end of this VBA Code Example.