Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
looping through userform controls JulieD Excel Programming 2 August 14th 04 02:13 PM
Help please with UserForm controls sa3214 Excel Programming 4 July 2nd 04 03:00 AM
Bmp vs Gif in Userform image controls Sandy-V[_2_] Excel Programming 0 January 14th 04 01:46 PM
Hyperlinks from UserForm Controls Nigel[_5_] Excel Programming 3 November 1st 03 01:21 PM
Add controls to UserForm Vyyk Drago Excel Programming 3 August 26th 03 01:22 PM


All times are GMT +1. The time now is 01:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"