text box ranges in userform

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings,
I know that I can range worksheet cell references in userform, but can I range the textboxes in that same userform?

Instead of doing this for 40 text boxes

Code:
    TextBox1 = ""
    TextBox2 = ""
    TextBox3 = ""
    TextBox4 = ""
    TextBox5 = ""
    TextBox6 = ""
    TextBox7 = ""
    TextBox8 = ""
    TextBox9 = ""
    TextBox10 = ""
    TextBox11 = ""
'all the way up to 40+ text boxes...

I would rather do something like this:

Code:
Range("TextBox1:textbox40") = ""

Not sure how to tweak this, the semicolon is not the correct syntax -appreciate any input - thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi,

one way:

Code:
Dim i As Integer
For i = 1 To 40
    Me.Controls("TextBox" & i).Text = ""
Next i

Dave
 
Upvote 0
Thanks Dave, worked great; I hadn't considered that way; so much cleaner - that's what I like about this forum, so many different ways of doing things, its pretty cool.
 
Upvote 0
Thanks Dave, worked great; I hadn't considered that way; so much cleaner - that's what I like about this forum, so many different ways of doing things, its pretty cool.

All programmers have their preferred way of doing things.

Glad suggestion helped.

Dave
 
Upvote 0
Why do you need to clear all these Textboxes?
When you unload your UserForm all the Textboxes loose their values.

Close your UserForm like this:
Unload Userform1
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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