Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default initializing multiple comboboxes

i am trying to initialize all the comboboxes in a userform by iterating
through them and setting their .list and their .listindex. values.

here is my code:

Private Sub UserForm_Initialize()
Dim ctl As Control
Dim WT As Range
Dim DT As Range

WT = Sheets("sheet2").Range("W_T")
DT = Sheets("sheet2").Range("D_T")

Me.Caption = ActiveCell.Value
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List = WT.Value
ctl.ListIndex = 0
End If
Next ctl
ComboBox7.List = DT.Value
ComboBox7.ListIndex = 0

TextBox1.Value = 0
End Sub


I am getting an error that says "object variable or with block variable
not set" on the line of code (elsewhere) that displays the userform
"VBA.UserForms.Add(UnitType).Show" This line has worked in the up till
now, so i am pretty sure that the problem is in the code above, and i
am pretty sure it is in the two lines that begin "ctl.list" and
"ctl.listindex". I was hoping and guessing that this syntax would
work, but it looks like i am wrong.

any suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default initializing multiple comboboxes

Try this

Dim ctl As Control
Dim WT
Dim DT

WT = Sheets("sheet2").Range("W_T")
DT = Sheets("sheet2").Range("D_T")

Me.Caption = ActiveCell.Value
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List = WT
ctl.ListIndex = 0
End If
Next ctl
ComboBox7.List = DT
ComboBox7.ListIndex = 0

TextBox1.Value = 0

--

HTH

RP
(remove nothere from the email address if mailing direct)


"natanz" wrote in message
ups.com...
i am trying to initialize all the comboboxes in a userform by iterating
through them and setting their .list and their .listindex. values.

here is my code:

Private Sub UserForm_Initialize()
Dim ctl As Control
Dim WT As Range
Dim DT As Range

WT = Sheets("sheet2").Range("W_T")
DT = Sheets("sheet2").Range("D_T")

Me.Caption = ActiveCell.Value
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List = WT.Value
ctl.ListIndex = 0
End If
Next ctl
ComboBox7.List = DT.Value
ComboBox7.ListIndex = 0

TextBox1.Value = 0
End Sub


I am getting an error that says "object variable or with block variable
not set" on the line of code (elsewhere) that displays the userform
"VBA.UserForms.Add(UnitType).Show" This line has worked in the up till
now, so i am pretty sure that the problem is in the code above, and i
am pretty sure it is in the two lines that begin "ctl.list" and
"ctl.listindex". I was hoping and guessing that this syntax would
work, but it looks like i am wrong.

any suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default initializing multiple comboboxes

thanks but that is not working. It seems like i need to use a "set"
statement somewhere. but i am not sure where. I am self taught at
this and there are apparently some major gaps.

advice?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default initializing multiple comboboxes

Hi

the ranges are not set

Try

Set WT = Sheets("sheet2").Range("W_T")
Set DT = Sheets("sheet2").Range("D_T")

carlos

"natanz" wrote in message
ups.com...
i am trying to initialize all the comboboxes in a userform by iterating
through them and setting their .list and their .listindex. values.

here is my code:

Private Sub UserForm_Initialize()
Dim ctl As Control
Dim WT As Range
Dim DT As Range

WT = Sheets("sheet2").Range("W_T")
DT = Sheets("sheet2").Range("D_T")

Me.Caption = ActiveCell.Value
For Each ctl In Me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List = WT.Value
ctl.ListIndex = 0
End If
Next ctl
ComboBox7.List = DT.Value
ComboBox7.ListIndex = 0

TextBox1.Value = 0
End Sub


I am getting an error that says "object variable or with block variable
not set" on the line of code (elsewhere) that displays the userform
"VBA.UserForms.Add(UnitType).Show" This line has worked in the up till
now, so i am pretty sure that the problem is in the code above, and i
am pretty sure it is in the two lines that begin "ctl.list" and
"ctl.listindex". I was hoping and guessing that this syntax would
work, but it looks like i am wrong.

any suggestions?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default initializing multiple comboboxes

No, because you need to load an array, not a range variable.

I tested it, it works.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"natanz" wrote in message
oups.com...
thanks but that is not working. It seems like i need to use a "set"
statement somewhere. but i am not sure where. I am self taught at
this and there are apparently some major gaps.

advice?



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
Multiple ComboBoxes Michael Excel Programming 2 October 25th 04 06:49 PM
Initializing a Form with multiple forms embedded bforster1 Excel Programming 2 July 14th 04 07:42 PM
Populate multiple comboboxes with same lists meansean Excel Programming 0 April 5th 04 10:30 AM
Populate multiple comboboxes with same lists Sean M. Excel Programming 1 April 5th 04 09:41 AM
Multiple ComboBoxes and TextBoxes on Userform Rich J Excel Programming 6 January 27th 04 07:51 PM


All times are GMT +1. The time now is 02:57 PM.

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"