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
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.
Click "Macros" and type "removeBlankTxtBox" below the macro name and click "Create" to create a new macro.
Type the following to capture errors if any:
On Error GoTo Err_removeBlankTxtBox:
Add the following code to check if the text box is blank and remove it if it's true:
If ActiveSheet.TextBox1.Value = "" Then
Add the following code to handle any errors:
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.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for