PC Review


Reply
Thread Tools Rate Thread

Create array

 
 
QB
Guest
Posts: n/a
 
      1st Dec 2009
I have a row in which I have an undefined number of merged cells (Varying in
the number of cells that each merged cell is comprised of). I now need to
populate a userform combobox with the values.

I tried doing

Me.combobox1.RowSource = "Sheet1!Q1:MN1"

but the cbo only has the first value appear. How can I get the full list of
the merged cell values into the cbo?

Thank you

QB
 
Reply With Quote
 
 
 
 
Tom Hutchins
Guest
Posts: n/a
 
      2nd Dec 2009
If they are really merged cells, all the data is in the first (topmost left)
cell. If the data is separated by some delimiting character, you can load the
combobox with a routine similar to this:

Private Sub UserForm_Initialize()
Dim DelimRng As Range
Dim x As Long, zzz
'identify the delimiting character
Const DelimChar = ","
'only need the first (topmost left) cell of the merged range
Set DelimRng = Sheets("Sheet1").Range("Q1")
'use SPLIT to populate an array variable
zzz = Split(DelimRng.Value, DelimChar)
'add the array items to the combobox
For x = LBound(zzz) To UBound(zzz)
Me.ComboBox1.AddItem Trim(zzz(x))
Next x
Set DelimRng = Nothing
End Sub

If you mean that your Q1:MN1 range includes several sets of merged cells,
you can load the combobox by looping through the whole range. Merged cells
are treated as a single cell. For example:

Private Sub UserForm_Initialize()
Dim SelRng As Range, c As Range
Const DelimChar = ","
Set SelRng = Sheets("Sheet1").Range("Q1:Z10")
For Each c In SelRng
If Len(Trim(c.Value)) > 0 Then
Me.ComboBox1.AddItem Trim(c.Value)
End If
Next c
Set SelRng = Nothing
End Sub

Hope this helps,

Hutch

"QB" wrote:

> I have a row in which I have an undefined number of merged cells (Varying in
> the number of cells that each merged cell is comprised of). I now need to
> populate a userform combobox with the values.
>
> I tried doing
>
> Me.combobox1.RowSource = "Sheet1!Q1:MN1"
>
> but the cbo only has the first value appear. How can I get the full list of
> the merged cell values into the cbo?
>
> Thank you
>
> QB

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Create an array JB Microsoft Excel Programming 7 2nd Feb 2008 03:33 PM
create array Al Microsoft Excel Programming 6 13th Jul 2007 08:29 PM
how do I create an array =?Utf-8?B?bG9zdA==?= Microsoft Excel Misc 6 7th Apr 2005 12:43 AM
how do I create an array =?Utf-8?B?YXJyYXlfZGVmaWNpZW50?= Microsoft Excel Misc 0 6th Apr 2005 09:53 PM
Create array function Yuriy Kuznetsov Microsoft Excel Programming 2 2nd Nov 2004 03:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:05 PM.