Make a string an object?

starl

Administrator
Joined
Aug 16, 2002
Messages
6,081
Office Version
  1. 365
Platform
  1. Windows
Isn't there a way of making a string an object?

example: I have objects: Form1, Form2, Form3
I want to run them thru a loop. So, I create a string "Form" & counter...
but how can I get that to become the object?

why am i doing this... cause I have several forms to clear - some have up to 20 boxes... and to have to clear each one....
Could swear I read there was a way..unless I totally misunderstood!

thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi starl,

Are you looking to perform an action on ALL of the forms or just some of them? If its all of them try using 'For Each' to loop through.
 
Upvote 0
a little confusion on my part..
I have a multipage form - mixture of comboboxes and textboxes.
I want to clear SPECIFIC boxes - not the entire page of the form.
My use of "Form" was just a way of referring to the different types of boxes.
 
Upvote 0
ok - so how can I use the For Each to go through the comboboxes on a page of my form??? I couldn't figure out what the collection is..
 
Upvote 0
Hi starl,

From the VBE Help section:

You can access the collection of controls on a UserForm using the Controls collection. For example, to hide all the controls on a UserForm, use code similar to the following:

For Each Control in UserForm1.Controls
Control.Visible = False
Next Control

HTH
 
Upvote 0
From within the UserForm module, something like this would cycle through (eg add this to a command button's click event to clear the comboboxes, or use it in the userform's Terminate event, use the UserForm1. qualifier rather than Me. if you're doing it outside the UserForm module etc etc): -

Code:
Dim ctr As Control

For Each ctr In Me.Controls
    If TypeName(ctr) = "ComboBox" Then MsgBox ctr.Name ' do your stuff here
Next ctr
 
Upvote 0
Solution

Forum statistics

Threads
1,214,800
Messages
6,121,641
Members
449,044
Latest member
hherna01

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