Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default Listbox Max Columns

EXCEL 2003
I am filling 2 listboxes. The first listbox is filled like this:

lr = LastRow(ThisWorkbook.Worksheets("Mesh"))
With ThisWorkbook.Worksheets("Mesh")
Set MeshInventory = .Range(.Cells(2, "A"), .Cells(lr, "K"))
End With
With Me.lbMeshInventory
.ColumnHeads = False 'can't use this feature here
.ColumnCount = MeshInventory.Columns.Count
.List = MeshInventory.Value
End With

Since this source is bound, it lest me have more than 10 columns in the
listbox. When the user double clicks an item on the first Listbox, I want
that item added to the second listbox. I'm pulling my hair out trying to
figure out how to make the second listbox bound so it can also have more than
10 columns. Dave Peterson posted something on 3/1/07 and said to use
..AddItem, but I get an error when the code gets to the 10th column.

thank you,
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox Max Columns

I think you would have to go back to your list source to pick up all eleven
columns.
It will only pick up the bound column value or the first column value by
default as the Value source from one list box to the other. To get a row of
eleven columns you would need and array or list to load the list box.

"steve" wrote:

EXCEL 2003
I am filling 2 listboxes. The first listbox is filled like this:

lr = LastRow(ThisWorkbook.Worksheets("Mesh"))
With ThisWorkbook.Worksheets("Mesh")
Set MeshInventory = .Range(.Cells(2, "A"), .Cells(lr, "K"))
End With
With Me.lbMeshInventory
.ColumnHeads = False 'can't use this feature here
.ColumnCount = MeshInventory.Columns.Count
.List = MeshInventory.Value
End With

Since this source is bound, it lest me have more than 10 columns in the
listbox. When the user double clicks an item on the first Listbox, I want
that item added to the second listbox. I'm pulling my hair out trying to
figure out how to make the second listbox bound so it can also have more than
10 columns. Dave Peterson posted something on 3/1/07 and said to use
.AddItem, but I get an error when the code gets to the 10th column.

thank you,
Steve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Listbox Max Columns

But you didn't say that you were exceeding 10 columns in that post--I hope I
wouldn't have suggested .additem if you had included that.

If you assign an array to the .list, then you can have more than 10 columns.
Your posted code isn't really using a bound control.

..rowsource = MeshInventory.address(external:=true)

would be bound to the worksheet.

I created a small userform with 2 listboxes and 2 commandbuttons. I put some
test data in Sheet1 A1:BB10 (just the cell's address)--but way more than 10
columns.

This was behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim rCtr As Long
Dim cCtr As Long
Dim lCtr As Long
Dim myArr As Variant

rCtr = -1
With Me.ListBox1
'since you can only change the last dimension,
'this array is transposed
'columns x rows instead of rows x columns
ReDim myArr(0 To .ColumnCount - 1, 0 To .ListCount - 1)
For lCtr = 0 To .ListCount - 1
If .Selected(lCtr) = True Then
rCtr = rCtr + 1
For cCtr = 0 To .ColumnCount - 1
myArr(cCtr, rCtr) = .List(lCtr, cCtr)
Next cCtr
End If
Next lCtr

If rCtr = -1 Then
'nothing selected
Beep
Else
ReDim Preserve myArr(0 To .ColumnCount - 1, 0 To rCtr)
Me.ListBox2.List = Application.Transpose(myArr)
End If

End With
End Sub
Private Sub UserForm_Initialize()
Dim MeshInventory As Range

With ThisWorkbook.Worksheets("Sheet1")
Set MeshInventory = .Range("A2:bb" & .Cells(.Rows.Count, "K").Row)
End With

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.ColumnHeads = False 'can't use this feature here
.ColumnCount = MeshInventory.Columns.Count
.List = MeshInventory.Value
End With

With Me.ListBox2
.ColumnHeads = False
.ColumnCount = Me.ListBox1.ColumnCount
End With

With Me.CommandButton1
.Caption = "Cancel"
.Cancel = True
End With

With Me.CommandButton2
.Caption = "Transfer to lb2"
.Default = True
End With
End Sub


steve wrote:

EXCEL 2003
I am filling 2 listboxes. The first listbox is filled like this:

lr = LastRow(ThisWorkbook.Worksheets("Mesh"))
With ThisWorkbook.Worksheets("Mesh")
Set MeshInventory = .Range(.Cells(2, "A"), .Cells(lr, "K"))
End With
With Me.lbMeshInventory
.ColumnHeads = False 'can't use this feature here
.ColumnCount = MeshInventory.Columns.Count
.List = MeshInventory.Value
End With

Since this source is bound, it lest me have more than 10 columns in the
listbox. When the user double clicks an item on the first Listbox, I want
that item added to the second listbox. I'm pulling my hair out trying to
figure out how to make the second listbox bound so it can also have more than
10 columns. Dave Peterson posted something on 3/1/07 and said to use
.AddItem, but I get an error when the code gets to the 10th column.

thank you,
Steve


--

Dave Peterson
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
Transferring from both columns of a listbox to another Edward Excel Discussion (Misc queries) 1 February 22nd 07 02:34 AM
ListBox with non contigous columns François Excel Programming 1 March 22nd 06 03:00 PM
Listbox with Bound Columns Vijay Bhatawdekar Excel Programming 0 February 11th 04 07:47 AM
Format columns in a ListBox? Soniya Excel Programming 1 October 12th 03 11:40 AM
Multi-columns in a ListBox Tom Atkisson Excel Programming 1 October 5th 03 10:27 PM


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