Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default array of userform controls

Hello,

Can I define an array of userform controls? This doesn't work- I get a
"type mismatch":

Dim userform_control As MSForms.Control
With GoalSeekwithValueRangeForm
For Each userform_control In .Controls (Array(.ChangingCellRefEdit.Name,
..SetCellRefEdit.Name))
...

Thanks as always,

Doug


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default array of userform controls

Doug,

Here is code I use to access the option buttons
on a particular form. You can probably adapt it to your needs.

Regards,
Jim Cone
San Francisco, USA

'-------------------------
Private Function SetButtonFont(ByRef objControl As MSForms.OptionButton)
Dim objButt As Object
For Each objButt In Me.ButtonsFrame.Controls
If TypeOf objButt Is MSForms.OptionButton Then objButt.Font.Bold = False
Next 'objButt
objControl.Font.Bold = True
Set objButt = Nothing
Set objControl = Nothing
End Function
'-------------------------



"Doug Glancy" wrote in message
...
Hello,

Can I define an array of userform controls? This doesn't work- I get a
"type mismatch":

Dim userform_control As MSForms.Control
With GoalSeekwithValueRangeForm
For Each userform_control In .Controls (Array(.ChangingCellRefEdit.Name,
..SetCellRefEdit.Name))

Thanks as always,
Doug


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default array of userform controls

Jim,

I'm only working with two controls, so I thought something analogous to

Worksheets(Array("Sheet1", "Sheet2"))

would be more compact than what I'm doing, which is like what you said, only
the If statement specifies the two controls' names:

With GoalSeekwithValueRangeForm
For Each userform_control In .Controls
If userform_control.Name = .SetCellRefEdit.Name Or _
userform_control.Name = .ChangingCellRefEdit.Name Then
...
Thanks,

Doug

"Jim Cone" wrote in message
...
Doug,

Here is code I use to access the option buttons
on a particular form. You can probably adapt it to your needs.

Regards,
Jim Cone
San Francisco, USA

'-------------------------
Private Function SetButtonFont(ByRef objControl As MSForms.OptionButton)
Dim objButt As Object
For Each objButt In Me.ButtonsFrame.Controls
If TypeOf objButt Is MSForms.OptionButton Then objButt.Font.Bold =
False
Next 'objButt
objControl.Font.Bold = True
Set objButt = Nothing
Set objControl = Nothing
End Function
'-------------------------



"Doug Glancy" wrote in message
...
Hello,

Can I define an array of userform controls? This doesn't work- I get a
"type mismatch":

Dim userform_control As MSForms.Control
With GoalSeekwithValueRangeForm
For Each userform_control In .Controls
(Array(.ChangingCellRefEdit.Name,
.SetCellRefEdit.Name))

Thanks as always,
Doug




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default array of userform controls

Hi Doug

Yes, add them to a custom Collection. Try this on a new userform containing
Textbox1, Textbox2, Textbox3, Textbox4, ...

Option Explicit 'top of userform module

Dim MyControls As Collection

Private Sub UserForm_Initialize()
Set MyControls = New Collection
MyControls.Add Me.TextBox1, "Txt1"
MyControls.Add Me.TextBox2, "Txt2"
MyControls.Add Me.TextBox3, "Txt3"
End Sub

Private Sub CommandButton1_Click()
Dim ctl As MSForms.Control 'or .TextBox
For Each ctl In MyControls
ctl.Text = Now
Next
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
Set MyControls = Nothing
End Sub

HTH. Best wishes Harald

"Doug Glancy" skrev i melding
...
Hello,

Can I define an array of userform controls?



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
Grouping Userform Controls ExcelMonkey[_190_] Excel Programming 1 February 23rd 05 02:49 PM
Userform Controls Nigel Excel Programming 5 December 30th 04 01:49 PM
Help please with UserForm controls sa3214 Excel Programming 4 July 2nd 04 03:00 AM
UserForm Controls References Nigel[_4_] Excel Programming 2 October 4th 03 01:55 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 07:11 PM.

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

About Us

"It's about Microsoft Excel"