How to Remove a Blank Text Box in VBA

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Remove a Blank Text Box in VBA
Add controls to a worksheet in Excel. (Comstock/Comstock/Getty Images)

Removing blank text boxes in Microsoft Excel using Visual Basic for Applications (VBA) is not as complicated as you may think. In VBA, you can use the worksheet name and the name of the text box to access its value. Use the "OLEObject" object to remove an object, such as a text box from a worksheet. This object represents an ActiveX control on a worksheet, it contains the "Delete" property which can be used to remove a control.

Skill level:

Other People Are Reading

Things you need

  • Microsoft Excel

Show MoreHide


  1. 1

    Launch Microsoft Excel, click the "Developer" tab and click the "Insert" icon located in the Controls pane. Click "Text Box" below ActiveX Controls and click any cell where you want to insert the text box. Add a new button using the same technique.

  2. 2

    Click "Macros" and type "removeBlankTxtBox" below the macro name and click "Create" to create a new macro.

  3. 3

    Type the following to capture errors if any:

    On Error GoTo Err_removeBlankTxtBox:

  4. 4

    Add the following code to check if the text box is blank and remove it if it's true:

    If ActiveSheet.TextBox1.Value = "" Then


    End If

  5. 5

    Add the following code to handle any errors:


    Exit Sub


    Resume Exit_removeBlankTxtBox:
  6. 6

    Switch back to Microsoft Office Excel and right-click the button. Click "Assign macro..." and click "removeBlankTxtBox." Click "OK." Click "Button 1" to execute your macro and remove the text box if it's blank.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.