View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
dtb dtb is offline
external usenet poster
 
Posts: 3
Default How to clear items on a form?

It's not elegant, but assuming you name all your TextBox controls
consistently (i.e. begin with txt) then the following will work.

Dim ctrl As Control

For Each ctrl In UserForm1.Controls
If Left(ctrl.Name, 3) = "txt" Then
ctrl.Text = ""
End If
Next

Just add this to the Click event of a button on your UserForm.



"Grd" wrote:

Hi,

I have a user form with details such as first name and last name. IF the
user wishes to start again, I would like a clear or reset button to clear the
fields that they have typed.

Is there a way to loop through each textbox to clear it to blank?

Thanks

G