Make a string an object?

starl

Administrator
Joined
Aug 16, 2002
Messages
5,983
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
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.
 

starl

Administrator
Joined
Aug 16, 2002
Messages
5,983
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
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.
 

starl

Administrator
Joined
Aug 16, 2002
Messages
5,983
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
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..
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329

ADVERTISEMENT

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
 

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
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
 
Solution

starl

Administrator
Joined
Aug 16, 2002
Messages
5,983
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
*lol* thank you both.
 

Forum statistics

Threads
1,143,614
Messages
5,719,719
Members
422,242
Latest member
hishamkhatri

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