text box ranges in userform

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
607
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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,995
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hi,

one way:

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

Dave
 
Upvote 0

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
607
Office Version
  1. 2019
Platform
  1. Windows
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

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,995
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
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

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,343
Office Version
  1. 2021
Platform
  1. Windows
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,191,681
Messages
5,987,984
Members
440,124
Latest member
dippy_egg

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