Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Read comboboxes into array

Hi. I have a form with 15 comboboxes. I populated the combo box list with
the following code:

Userform1.ComboBox1.List =
Price.Range("LMU").Resize(Price.Range("LMU").Rows. Count - 1).Value

I copied the above code 15 times, because the list for each box is exactly
the same. Can I read the comboboxes into an array, and then populate the
aray with a single statement as above?

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Read comboboxes into array

Steph, this code assumes you only have 15 combos on your
form - if you have more, you should put those 15 in a
frame and loop through the frame's controls rather than
the forms

Rgds

Rog


Dim ctl As Control

For Each ctl In me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List =Price.Range("LMU").Resize(Price.Range
("LMU").Rows.Count - 1).Value
End If
Next

-----Original Message-----
Hi. I have a form with 15 comboboxes. I populated the

combo box list with
the following code:

Userform1.ComboBox1.List =
Price.Range("LMU").Resize(Price.Range("LMU").Rows .Count -

1).Value

I copied the above code 15 times, because the list for

each box is exactly
the same. Can I read the comboboxes into an array, and

then populate the
aray with a single statement as above?

Thanks!


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Read comboboxes into array

Hi Rog,

Thanks for the response. My original post was an incredibly simplified view
of my form! I have hundreds of comboboxes and text boxes on multipage tabs.
Your looping code will work great, but would mean I'd have to draw frames
arounds tons of stuff.

Can it be done without frames? can your first line of code be
For Each ctl in Array1 instead of
For Each ctl in me.Controls?

Thanks a bunch!

"Rog" wrote in message
...
Steph, this code assumes you only have 15 combos on your
form - if you have more, you should put those 15 in a
frame and loop through the frame's controls rather than
the forms

Rgds

Rog


Dim ctl As Control

For Each ctl In me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List =Price.Range("LMU").Resize(Price.Range
("LMU").Rows.Count - 1).Value
End If
Next

-----Original Message-----
Hi. I have a form with 15 comboboxes. I populated the

combo box list with
the following code:

Userform1.ComboBox1.List =
Price.Range("LMU").Resize(Price.Range("LMU").Rows .Count -

1).Value

I copied the above code 15 times, because the list for

each box is exactly
the same. Can I read the comboboxes into an array, and

then populate the
aray with a single statement as above?

Thanks!


.



  #4   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Read comboboxes into array

Yes, the loop can certainly be changed; it just means you
will have to populate your own array/collection
beforehand, eg

Dim col_15Combos As New Collection
Dim ctl As Control

col_15Combos.Add ComboBox1
col_15Combos.Add ComboBox2
....
col_15Combos.Add ComboBox15

For Each ctl In col_15Combos
ctl.List = your range

Next

-----Original Message-----
Hi Rog,

Thanks for the response. My original post was an

incredibly simplified view
of my form! I have hundreds of comboboxes and text boxes

on multipage tabs.
Your looping code will work great, but would mean I'd

have to draw frames
arounds tons of stuff.

Can it be done without frames? can your first line of

code be
For Each ctl in Array1 instead of
For Each ctl in me.Controls?

Thanks a bunch!

"Rog" wrote in

message
...
Steph, this code assumes you only have 15 combos on your
form - if you have more, you should put those 15 in a
frame and loop through the frame's controls rather than
the forms

Rgds

Rog


Dim ctl As Control

For Each ctl In me.Controls
If TypeName(ctl) = "ComboBox" Then
ctl.List =Price.Range("LMU").Resize

(Price.Range
("LMU").Rows.Count - 1).Value
End If
Next

-----Original Message-----
Hi. I have a form with 15 comboboxes. I populated the

combo box list with
the following code:

Userform1.ComboBox1.List =
Price.Range("LMU").Resize(Price.Range

("LMU").Rows.Count -
1).Value

I copied the above code 15 times, because the list for

each box is exactly
the same. Can I read the comboboxes into an array, and

then populate the
aray with a single statement as above?

Thanks!


.



.

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
How to Read Worksheet Data into VBA Array? Peter Bernadyne Excel Discussion (Misc queries) 1 July 12th 06 05:19 PM
using VB to read in a column of values of varying length into an array [email protected] Excel Worksheet Functions 2 June 12th 06 10:08 PM
Excel, read in an array AustinJames Setting up and Configuration of Excel 4 September 20th 05 03:18 PM
Read in Array Leigh Excel Programming 1 May 5th 04 09:18 AM
Read Range Data into Array Stratuser Excel Programming 1 April 26th 04 06:46 PM


All times are GMT +1. The time now is 04:37 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"