Clearing Form

  • Thread starter Thread starter PEno1
  • Start date Start date
P

PEno1

Hi, I would to clear an Excel form (Text boxes and check boxes) after the
user has clicked the Submit button.
Can any one tell me the code to do this please?

TIA,
PE1
 
Hi Pe1

one way among several:

Private Sub CommandButton1_Click()
Dim C As MSForms.Control
For Each C In Me.Controls
Select Case TypeName(C)
Case "TextBox"
C.Text = ""
Case "ComboBox", "ListBox"
C.ListIndex = -1
Case "CheckBox", "OptionButton"
C.Value = False
Case Else
End Select
Next
End Sub

HTH. Best wishes Harald
 
presuming your form is 'userform1' i *think* this should work...

sub ClearAll()
on error resume next
for each control in userform1.controls
control.visible=false
control.value=false
control.text=""
next control
end sub

the 'on error...' avoids problems of controls not having some properties,
but also means that other problems might go un-noticed - maybe someone else
has a better solution?

hth

tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top