Clear all Text boxes and Combo Boxes using a Clear button (VBA)


  1. Goto Developers Tab.
  2. Click on "Insert"
  3. Select Button (Form Control)
  4. Right Click on the button created and select "Assign Macro"
  5. Give the Macro Name and select OK.
  6. Then add the following Macro code:
Private Sub CommandButton2_Click()
Dim c As Control
Dim a As Control
For Each c In UserForm1.Controls
    If TypeName(c) = "TextBox" Then
    c.Value = ""
    End If
Next c
UserForm1.TextBox1.SetFocus

For Each a In UserForm1.Controls
If TypeName(a) = "ComboBox" Then
a.Value = ""
End If
Next a
UserForm1.TextBox1.SetFocus
End Sub

No comments:

Post a Comment

Thank You.

https://linwintech.blogspot.com/