Excel VBA: How to Delete a Worksheet Button

VBA & macros · Updated November 3, 2026

Excel VBA: How to Delete a Worksheet Button

To delete a button from an Excel worksheet, select the button itself and press Delete; for a Form Control button, right-click it first if a normal click runs its macro. If you need to remove it with VBA, delete its shape or OLEObject by name, depending on whether it is a Form Control or an ActiveX button.

First identify what kind of button it is

Excel buttons are objects placed on top of worksheet cells, not cell contents. Deleting one does not remove the cells beneath it or normally change their data. The selection method and the VBA collection to use depend on the button type.

  • Form Control button: A built-in Excel control that can be assigned to a macro. It is usually straightforward to select from its border or the Selection Pane. Its assigned macro can be changed or removed without deleting the button.
  • ActiveX CommandButton: A control with additional properties and event code, such as a click event procedure. In desktop Excel for Windows, Design Mode lets you select it without activating it.
  • Shape used as a button: A rectangle, icon, or other drawing object that may have a macro assigned. It is deleted like any other shape.

If you are unsure, right-click the object and look at the available commands, or find its name in the Selection Pane. ActiveX controls can also be selected while Developer > Design Mode is turned on. A visible object that looks like a button is not necessarily a control: it may just be a shape with text and a macro assignment.

Delete a button manually in Excel for Windows

For a Form Control button, right-click the button and choose Cut, or select it and press Delete. A normal left-click may run the assigned macro rather than select the control. If the right-click menu is awkward or the button is small, the Selection Pane is often the most reliable option:

  1. Open the worksheet that contains the button.
  2. Choose Home > Find & Select > Selection Pane.
  3. In the pane, select the object name that corresponds to the button. Click the listed objects to see which one is selected on the sheet.
  4. Press Delete, or use the pane’s visibility controls to hide objects temporarily while identifying them.

For an ActiveX button, choose Developer > Design Mode, click the button’s border to select it, and press Delete. Turn Design Mode off when finished. Design Mode prevents the control from responding to its normal click event while you work on it. If the Developer tab is missing, enable it in Excel’s ribbon settings; it is a tab setting, not a workbook requirement.

After deleting the object, check that the intended button disappeared and that nearby controls or shapes remain. If you selected the wrong object, use Ctrl+Z on Windows to undo a manual deletion. On a Mac, use Command+Z. A Mac keyboard’s Delete key generally behaves like Backspace on a Windows keyboard, but it still deletes a selected worksheet object.

Delete a button with VBA by its name

Use VBA when a button must be removed as part of a controlled workbook task or when selecting it manually is difficult. First identify the worksheet tab name and the object name. The visible caption on a button—such as “Run Report”—may not be its object name, which could instead be “Button 1” or “CommandButton1.” The Selection Pane can help identify shape names; for an ActiveX control, use Design Mode and its Properties window to inspect the name.

The following example removes a named Form Control button or ordinary shape from a worksheet. Change both names to match the workbook. The object is found in the worksheet’s Shapes collection.

Option Explicit

Sub DeleteFormButton()
    Dim ws As Worksheet

    ' Change Sheet1 and Button 1 to the actual worksheet and object names.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ws.Shapes("Button 1").Delete
End Sub

To remove an ActiveX CommandButton instead, use the worksheet’s OLEObjects collection. The name in the example is an object name, not necessarily the text displayed on the button.

Option Explicit

Sub DeleteActiveXButton()
    Dim ws As Worksheet

    ' Change Sheet1 and CommandButton1 to the actual names.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ws.OLEObjects("CommandButton1").Delete
End Sub

Run the appropriate procedure from the VBA editor or assign it to a different control. If the named object does not exist, VBA will report an error; check spelling, worksheet name, and control type rather than assuming the displayed caption is the name. These examples intentionally target one object. Avoid broad deletion code until you have confirmed exactly which controls it will affect.

Where to put the code and how to run it

In Excel for Windows, press Alt+F11 to open the Visual Basic Editor. Choose Insert > Module, paste the procedure into the new standard module, then return to Excel. You can run it from the editor with the cursor inside the procedure by pressing F5, or run it from Excel through Developer > Macros. On many Mac keyboards, opening the editor uses Option+F11 or Fn+Option+F11, depending on keyboard settings; Excel for Mac also provides the Visual Basic Editor through its Developer tools.

Save a copy of the workbook before running a macro. VBA actions cannot be reversed with Ctrl+Z or Command+Z. If the workbook needs to retain VBA code, save it in a macro-enabled format such as .xlsm; a standard .xlsx file does not store VBA macros. Excel for the web cannot run VBA macros, so use the desktop app for these procedures.

What deleting the button does—and does not do

Removing a button deletes that worksheet object. It does not automatically delete the macro assigned to a Form Control button, and it does not erase a worksheet’s ActiveX event procedure from the VBA project. Those pieces of code may remain unused until you remove or repurpose them. Conversely, removing a macro does not necessarily remove the button: it can remain visible but no longer perform the expected action.

Before removing an object from a shared workbook, consider whether other users rely on it or whether it is part of a documented workflow. If you only want to stop a Form Control button from running code, right-click it and choose Assign Macro, then change or clear its assignment if that option is available. That preserves its appearance and position. For ActiveX, its event code and properties are managed separately in the VBA editor and Properties window.

Common problems and practical fixes

  • Clicking runs the macro. Right-click a Form Control button or select it through the Selection Pane. For an ActiveX control, turn on Developer > Design Mode first.
  • The button is hard to select. Open Home > Find & Select > Selection Pane, then select the object by name. This is especially useful when objects overlap or sit partly outside the visible area.
  • VBA says the subscript is out of range. The worksheet name or object name may be wrong, or the target may not be in the collection used by the code. Confirm that the control is a shape/Form Control or an ActiveX OLEObject.
  • The macro is missing after saving. Check whether the file was saved as .xlsx. Save a copy as .xlsm if the workbook must keep its VBA project.
  • The control is visible but cannot be changed in Excel for the web. Open the workbook in desktop Excel. VBA is not supported for running in Excel for the web, and ActiveX controls are a Windows desktop feature.

Windows, Mac, and web differences

These steps primarily describe Microsoft 365 Excel for Windows. Form Controls and ordinary shapes are the most portable choices when a workbook is used across platforms, although ribbon labels and keyboard behavior can vary. ActiveX controls are not supported in Excel for Mac, so a workbook containing one may not offer the same ability to select, edit, or use it on a Mac. Excel for the web also does not run VBA, so a macro-based deletion needs the desktop version.

On Mac, enable the Developer tab through Excel’s ribbon and toolbar settings, then use the available desktop tools for supported controls. If a workbook must work on Windows, Mac, and the web, consider replacing an ActiveX button with a Form Control or a shape and provide a non-macro alternative for web users. Do not assume that a control’s behavior will transfer simply because its visual appearance does.

Frequently Asked Questions

How do I delete a button without running its macro?
For a Form Control, right-click it and choose Cut, or select it in Home > Find & Select > Selection Pane and press Delete. For an ActiveX button, turn on Developer > Design Mode before selecting and deleting it.

Does deleting a button delete its VBA macro?
No. Deleting the worksheet object does not generally remove the macro procedure from the VBA project. You can leave the code in place, reuse it, or remove it separately if it is no longer needed.

Can I delete a button with VBA?
Yes. Use the worksheet’s Shapes collection for a Form Control button or shape, and its OLEObjects collection for an ActiveX control. Use the object’s actual name, which can differ from the button caption.

Can I undo a VBA deletion with Ctrl+Z?
No. Excel’s regular undo history does not reverse changes made by a VBA macro. Save a separate copy before running code; manual deletion can usually be undone with Ctrl+Z on Windows or Command+Z on Mac.

Why can’t I select or delete an ActiveX button on a Mac?
Excel for Mac does not support ActiveX controls in the same way as Excel for Windows. Make the change in desktop Excel for Windows, or replace the control with a supported Form Control or shape if the workbook needs cross-platform use.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.