Clear text from text box using VBA

ElBenno

Board Regular
Joined
Jun 3, 2005
Messages
97
Hi,
Does anyone have some code that i can assign to a button to clear the content of a text box in my worksheet?

Kindest Regards,

ben
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

ElBenno

Board Regular
Joined
Jun 3, 2005
Messages
97
work sheet is called Breach Form, text box is called TextBox4
 

ElBenno

Board Regular
Joined
Jun 3, 2005
Messages
97
Private Sub Submit_Click()
Dim ws As Worksheet
Dim i As Integer
Set ws = Sheets("Register")

' Return data to the worksheet
With ws
.Range("A4") = TextBox1.Value
.Range("B4") = TextBox2.Value
.Range("C4") = TextBox3.Value
.Range("D4") = TextBox4.Value
.Range("E4") = TextBox5.Value
.Range("F4") = TextBox6.Value
.Range("G4") = TextBox8.Value
.Range("H4") = TextBox10.Value
.Range("I4") = TextBox11.Value
End With
' Clear the TextBoxes
For i = 1 To 11
TextBox(i).Value = ""
Next i

End Sub

This is comming up with the following issue: Compile Error Sub or Function not defined (on the TextBox(i).Value).

thanks
 

Forum statistics

Threads
1,175,931
Messages
5,900,381
Members
434,829
Latest member
Azuki96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top