Log in
x
or
x
x
Register
x

or
0
0
0
s2sdefault

How to clear contents of textbox when clicked in Excel?

Normally, for clearing old contents of a textbox (ActiveX Control), you have to get into the textbox, select the whole contents and then press the Backspace or Delete key. How to clear all contents quickly in a textbox? This article will show you a VBA method to quickly clear contents of a textbox when just double clicking on it.

Clear contents of textbox when clicked with VBA code


Clear contents of textbox when clicked with VBA code


The following VBA code can help you quickly clear contents of a textbox when double-clicking on it. Please do as follows.

1. If a textbox has already existed in the worksheet, please turn on the Design Mode by clicking Developer > Design Mode. See screenshot:

Or you can also insert a textbox by clicking Developer > Insert > Text Box (ActiveX Control). See screenshot:

2. Right-click the textbox and click View Code from the context menu. See screenshot:

3. In the opening Microsoft Visual Basic for Applications window, please replace the original VBA code in the Code window with below VBA code.

VBA code: Clear contents of a textbox when double-clicking on it

Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  If Not iGblInhibitTextBoxEvents Then
    TextBox1.Value = ""
  End If
End Sub

Note: In the code, TextBox1 is the name of the textbox you will clear contents from. Please change it to your own.

4. Press the Alt + Q keys to exit the Microsoft Visual Basic for Applications window.

5. Turn off the Design Mode.

From now on, when double-clicking a textbox, its contents will be cleared immediately.


Related articles:


Recommended Productivity Tools

Office Tab

gold star1 Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.

Kutools for Excel

gold star1 Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!

gold star1 200 New Features for Excel, Make Excel Much Easy and Powerful:

  • Merge Cell/Rows/Columns without Losing Data.
  • Combine and Consolidate Multiple Sheets and Workbooks.
  • Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
  • Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
  • More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...

Screen shot of Kutools for Excel

btn read more      btn download     btn purchase

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.