A textbox is a common element in an Excel spreadsheet to add notes or additional information. However, sometimes we need to hide this textbox from the worksheet. Using the visual-basic code, we can perform such an operation efficiently. In the article, we are going to demonstrate the step-by-step procedure to hide the textbox using Excel VBA. If you are also curious about it, download our practice workbook and follow us.
Download Practice Workbook
Download this practice workbook for practice while you are reading this article.
Insert Textbox in Excel Worksheet
Before showing the textbox hiding procedure, we will first demonstrate to you how to insert a textbox in Excel. The steps of this process are given below:
📌 Steps:
- First of all, in the Insert tab, click on the Text Box command from the Text group.
- You will notice that the mouse cursor will change.
- Now, drag your mouse to insert the textbox in the worksheet.
- The textbox will appear in front of you.
- After that, write down a text inside the text box and format it according to your desire. Here, we write down our website name ExcelDemy.
- Our textbox is ready.
Step-by-Step Procedure to Hide Textbox Using Excel VBA
Now, we will demonstrate to you the step-by-step procedure to hide the textbox using the VBA in Excel. We are going to hide the textbox which we inserted a while ago.
📚 Note:
All the operations of this article are accomplished by using Microsoft Office 365 application.
Step 1: Launching Visual Basic Editor Dialog Box
In the first step, we are going to launch the Visual Basic Editor dialog box so that we can write a VBA code to hide the textbox in Excel.
- To start the approach, go to the Developer tab and click on Visual Basic. If you don’t have that, you have to enable the Developer tab. Or You can also press ‘Alt+F11’ for opening the Visual Basic Editor.
- As a result, a dialog box will appear.
- Now, in the Insert tab on that box, click the Module option.
- Then, a white empty editor interface will appear in front of you.
- Our first job is completed.
Thus, we can say that we have completed the first step of our task to hide the textbox.
Step 2: Writing Suitable VBA Code
In this step, we will write down the VBA code, which will hide the textbox from our worksheet.
- At first, click on the empty interface.
- Now, write down the following code in the box.
Sub Hide_Textbox()
Sheet1.Shapes("TextBox2").Visible = False
End Sub
- After that, press ‘Ctrl+S’ to save the code.
- Then, close the Editor tab.
Hence, we can say that we have accomplished the second step of our task to hide the textbox.
Read More: How to Add Text to Textbox Using Excel VBA (3 Effective Ways)
Step 3: Run and Get Result
In the last step, we will run the VBA code and hide our textbox.
- First, in the Developer tab, click on the Macros option.
- A new dialog box called Macros will appear.
- Now, select the Hide_Textbox option.
- Afterward, click on the Run button to run this code.
- You will notice that the textbox will hide from the worksheet.
Finally, we can say that our VBA code works successfully, and we are able to hide the textbox from our Excel spreadsheet.
Read More: How to Use VBA to Get Value from Userform Textbox in Excel
Conclusion
That’s the end of this article. I hope that this article will be helpful for you and you will be able to hide the textbox using Excel VBA. Please share any further queries or recommendations with us in the comments section below if you have any other questions or recommendations.
Don’t forget to check our website, ExcelDemy, for several Excel-related problems and solutions. Keep learning new methods and keep growing!