Clearing textboxes in userform error

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi i have the code below where i am trying to clear text boxes, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18 and 19 but i get an error on the 'For x = 10 To 19' line, please can you advice?
VBA Code:
Private Sub CommandButton3_Click()
Dim x As Integer
For x = 1 To 7
For x = 10 To 19
Me.Controls("textbox" & x).Value = ""
Next x
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You can't have two For statements like that using the same loop variable. You'd be better off just looping from 1 to 19 and then doing nothing when x is 8 or 9.
 
Upvote 0
For example:

VBA Code:
Private Sub CommandButton3_Click()
Dim x As Integer
For x = 1 To 19
   Select Case x
     Case 8, 9
         ' do nothing
     Case else
         Me.Controls("textbox" & x).Value = ""
   End Select
Next x
End Sub
 
Upvote 0
wow that has worked great thank you for your help much appreciated
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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
Back
Top