CommandButton is used to run or execute a macro or procedure. It performs a task or an action when a user clicks on a command button. Command Button can be used on the WorkSheet. Please find more details about ActiveX CommandButton Control in the following chapter. You can see how we are adding or deleting command button on the Worksheet.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

VBA ActiveX CommandButton Control on the Worksheet

Please find more details about VBA ActiveX Command Button Control on the Worksheet.

  1. Go To Developer Tab and then click Insert from the Controls group.
  2. Click on the Command Button from the ActiveX Controls group.
  3. Drag a Command Button on the Worksheet.
  4. Right click on the Command Button, before that Design Mode should be turned ON.
  5. Click on properties from the available list.
  6. On the left side find ‘Caption’ from the available properties of a Command Button .
  7. On the right side mention as ‘Click’. Please find the below screen shot for the same.
  8. Now, Double click on the Command Button (Click). Or right click on command button and click view code.
  9. Now you can see the following code in the VBA Editor window.
  10. Private Sub CommandButton21_Click()
    End Sub
  11. Now add the following code in between above procedure.
  12. Code:

    Private Sub CommandButton21_Click()
    MsgBox "Hi, Welcome to"
    End Sub
  13. Now, Press ‘F5’ to run the code. You can see the following Output. It is shown in the following Screen Shot.
  14. output:

Delete CommandButton Control on the Worksheet using VBA

Please find the below code, it will show you how to delete or remove a command button on the worksheet. In the below example, its deleting the command button named ‘CommandButton1’ which is on the worksheet named ‘Sheet11’. Here Delete is the property of Shape object.

Sub Delete_CommandButton()
End Sub


  1. rimmy September 4, 2015 at 3:15 AM - Reply

    i want to copy file1 into sheet1 of the master file and file2 into sheet2 of the master file using command button macro
    vba code. please how to write the code for that.

    Thank you.

  2. Kalidass.s January 28, 2016 at 6:22 PM - Reply

    how to control a comment button with another one command button.

    there is two command button in a sheet called
    command button-1 and command button-2

    command button-1 contains the following macro

    so I want to activate the command button-1 by pressing the command button-2

    please give me a solution

    • PNRao January 30, 2016 at 10:57 PM - Reply

      Hi Kalidas,

      Command button is having two properties to handle your requirement.

      Method 1. Enabled property of Command button

      Commandbutton1.Enabled=True ‘This will allow user to click on the button to execute the code inside the command button event.
      Commandbutton1.Enabled=False ‘It will not execute the code even after clicking on it.

      Method 2: Visible Property of the Command button
      Commandbutton1.Visible=True ‘it will display the commandbutton
      Commandbutton1.Visible=False’it will hide the commandbutton

      Hope this helps!

  3. Prince Toms June 21, 2016 at 3:33 PM - Reply

    How can i use toggle button to delete rows and columns ?

Leave A Comment

Related pages

vba vbyesnomsgbox vba exampleslookup excel tutorialvba save excel fileunlock protected workbookvba macros excelunlocking excel passwordcomment in excel vbashortcut keys excellearn vba programmingcase vba excelscrum call formatexcel advanced filter criteria range examplesrun macros in excel 2007unlock excel worksheetsql basics commandsexcel auto row heightproject tracker template in excelvba read text filehow do i hide a column in excelhow to unprotect password protected excel sheetexcel vba programming for dummies pdfvba create comboboxvba excel forms for data entryexcel vba loopnested vlookupsindex formula excel 2007how to create a 3d pie chart in excelhow to delete worksheet in excelmacros in excel tutorial for beginnersvba print functionvba application.waitdelete duplicate data excelvbscript check if file existsvba current directoryunlock password protected excel spreadsheetcost estimate spreadsheet templateproc sql tutorialms excel hyperlinkdashboard examples excelhow to learn vbamacro remove blank rowsuser defined functions in vbatextbox codeend vbaexcel vba activeworkbook.saveaswhat is a logical function in excelworkbooks closecombobox in excel vbahow to unhide all columnssas & sqlsql interview queries pdfvba range offsetadvanced pie charts in excelsimple gantt chart excel templateexcel 2010 unprotect workbook without passwordvba loop examplematch vbawhat is meant by vlookup in excelvba cutvba datediffgoto excel vbaexcel usedrangesas coding basicsmacros in excel for beginnersmacro to insert blank rows in excelcreate dashboards in excelvba as integerexplain vlookuphow to create a userform in excel 2010excel vba exampleinstr excelvlookup ref errorproject management timeline templatesum if function in excelexcel blank rowsexcel 2007 dashboard tutorialprotecting cells in excel 2007