move item from one listbox to another listbox
You could also use:
..List(.ListCount - 1, 1) _
= format(Me.ListBox1.List(Me.ListBox1.ListIndex, 1), "mm/dd/yyyy")
And alternative to the headers may be to add a couple of labels above the
listbox that describ each of the fields.
steve wrote:
Thank you for both of your replies.
The AddItem method is putting the values from Listbox1 into Listbox2, but it
loses the format. If my second column is a date, then it just gives me the
serial number. How do you get around this?
Is there a workaround that you can suggest? Like putting Listbox1 into a
temporary range on a worksheet, then filling Listbox2 so it can have headers?
thanks,
Steve
"Dave Peterson" wrote:
Headers come from worksheet ranges. So if you use .additem, you can't have
headers.
Option Explicit
Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If Me.ListBox1.ListIndex = -1 Then Exit Sub
With Me.ListBox2
'.AddItem ListBox1.Value
'or
.AddItem Me.ListBox1.List(Me.ListBox1.ListIndex)
.List(.ListCount - 1, 1) = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.ColumnCount = 2
.RowSource = Worksheets("sheet1").Range("a2:b4").Address(extern al:=True)
.ColumnHeads = True
End With
With Me.ListBox2
.ColumnCount = Me.ListBox1.ColumnCount
.Clear
End With
End Sub
steve wrote:
Listbox1 is populated from a worksheet range, and has Column headers. Right
now I can move an item from Listbox1 to Listbox2 for a single column listbox.
How can I do this for multicolumn listboxes?
Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If Listbox1.ListIndex = -1 Then Exit Sub
Listbox2.AddItem Listbox1.value
End If
End Sub
Also, is there anyway for Listbox2 to have Column headers?
thanks,
Steve
--
Dave Peterson
--
Dave Peterson
|