Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Userform Controls
Hi All
I have a set of controls on a userform, named x1, x2, x3 ........... xn etc Is there a way of setting these controls in a loop eg for i = 1 to n set control x of i to something next i I am not sure how to point to a named control by constructing a string for the name? Help! -- Cheers Nigel |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Userform Controls
Nigel,
As long as you have a structured naming convention, you could use code like this that gets the value from each textbox on the form Dim ctl As Control For Each ctl In Me.Controls If TypeName(ctl) = "TextBox" Then MsgBox ctl.Text End If Next ctl -- HTH RP (remove nothere from the email address if mailing direct) "Nigel" wrote in message ... Hi All I have a set of controls on a userform, named x1, x2, x3 ........... xn etc Is there a way of setting these controls in a loop eg for i = 1 to n set control x of i to something next i I am not sure how to point to a named control by constructing a string for the name? Help! -- Cheers Nigel |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Userform Controls
To answer your specific question, you could use Controls("X" & i).
You may also find John Walkenbach's object-oriented solution useful. See Handle Multiple UserForm Buttons With One Subroutine http://j-walk.com/ss/excel/tips/tip44.htm "Nigel" wrote: Hi All I have a set of controls on a userform, named x1, x2, x3 ........... xn etc Is there a way of setting these controls in a loop eg for i = 1 to n set control x of i to something next i I am not sure how to point to a named control by constructing a string for the name? Help! -- Cheers Nigel |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Userform Controls
Thanks Bob, that is part of the problem solved. My challenge is with a
subset of controls of the same type I wish to act on. I have a set of code linked to controls named c1 to cn, an event from anyone of these acts on another control named x1, x2 to xn etc. Whichever control c1 to cn is pressed the same code for x1 to xn needs to run. Somehow I need to pass the number of the cn control to the code to act on the xn control. Any thoughts? -- Cheers Nigel "Bob Phillips" wrote in message ... Nigel, As long as you have a structured naming convention, you could use code like this that gets the value from each textbox on the form Dim ctl As Control For Each ctl In Me.Controls If TypeName(ctl) = "TextBox" Then MsgBox ctl.Text End If Next ctl -- HTH RP (remove nothere from the email address if mailing direct) "Nigel" wrote in message ... Hi All I have a set of controls on a userform, named x1, x2, x3 ........... xn etc Is there a way of setting these controls in a loop eg for i = 1 to n set control x of i to something next i I am not sure how to point to a named control by constructing a string for the name? Help! -- Cheers Nigel |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Userform Controls
Thanks, most helpful.
-- Cheers Nigel "Tushar Mehta" wrote in message ... To answer your specific question, you could use Controls("X" & i). You may also find John Walkenbach's object-oriented solution useful. See Handle Multiple UserForm Buttons With One Subroutine http://j-walk.com/ss/excel/tips/tip44.htm "Nigel" wrote: Hi All I have a set of controls on a userform, named x1, x2, x3 ........... xn etc Is there a way of setting these controls in a loop eg for i = 1 to n set control x of i to something next i I am not sure how to point to a named control by constructing a string for the name? Help! -- Cheers Nigel |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Userform Controls
Ok, Tushar Mehta has provide answer in sub thread.
Controls("name") -- Cheers Nigel "Nigel" wrote in message ... Thanks Bob, that is part of the problem solved. My challenge is with a subset of controls of the same type I wish to act on. I have a set of code linked to controls named c1 to cn, an event from anyone of these acts on another control named x1, x2 to xn etc. Whichever control c1 to cn is pressed the same code for x1 to xn needs to run. Somehow I need to pass the number of the cn control to the code to act on the xn control. Any thoughts? -- Cheers Nigel "Bob Phillips" wrote in message ... Nigel, As long as you have a structured naming convention, you could use code like this that gets the value from each textbox on the form Dim ctl As Control For Each ctl In Me.Controls If TypeName(ctl) = "TextBox" Then MsgBox ctl.Text End If Next ctl -- HTH RP (remove nothere from the email address if mailing direct) "Nigel" wrote in message ... Hi All I have a set of controls on a userform, named x1, x2, x3 ........... xn etc Is there a way of setting these controls in a loop eg for i = 1 to n set control x of i to something next i I am not sure how to point to a named control by constructing a string for the name? Help! -- Cheers Nigel |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
looping through userform controls | Excel Programming | |||
Help please with UserForm controls | Excel Programming | |||
Bmp vs Gif in Userform image controls | Excel Programming | |||
Hyperlinks from UserForm Controls | Excel Programming | |||
Add controls to UserForm | Excel Programming |