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 move item from one listbox to another listbox

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default move item from one listbox to another listbox

Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If ListBox1.ListIndex = -1 Then Exit Sub
ListBox2.AddItem ListBox1.Value
ListBox2.List(ListBox2.ListCount - 1, 1) =
ListBox1.List(ListBox1.ListIndex, 1)

End Sub

as to columnheads, no. Columne heads are pulled from the row above the bound
data, the second isn't bound.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"steve" wrote in message
...
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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default move item from one listbox to another listbox

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default move item from one listbox to another listbox

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default move item from one listbox to another listbox

Try this

Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Const TARGET_COL As String = "AA"
Dim LastRow As Long
Dim FirstCol As Long
Dim NumCols As Long
Dim FirstRow As Long

With Me

If .ListBox1.ListIndex = -1 Then Exit Sub

FirstRow = .Range(.ListBox1.ListFillRange).Row - 1
FirstCol = .Range(.ListBox1.ListFillRange).Cells(1, 1).Column
NumCols = .Range(.ListBox1.ListFillRange).Columns.Count

.Cells(FirstRow, FirstCol).Resize(, NumCols).Copy .Cells(FirstRow,
TARGET_COL)

LastRow = .Cells(.Rows.Count, TARGET_COL).End(xlUp).Row
With .ListBox1

Me.Range(.ListFillRange).Cells(1,
1).Offset(.ListIndex).Resize(1, NumCols).Copy Me.Cells(LastRow + 1, "AA")
Me.ListBox2.ListFillRange = Me.Cells(1,
TARGET_COL).Resize(LastRow + 1, NumCols).Address
End With
End With
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"steve" wrote in message
...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,814
Default move item from one listbox to another listbox

I get an error message for ".ListFillRange"

steve

"Bob Phillips" wrote:

Try this

Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Const TARGET_COL As String = "AA"
Dim LastRow As Long
Dim FirstCol As Long
Dim NumCols As Long
Dim FirstRow As Long

With Me

If .ListBox1.ListIndex = -1 Then Exit Sub

FirstRow = .Range(.ListBox1.ListFillRange).Row - 1
FirstCol = .Range(.ListBox1.ListFillRange).Cells(1, 1).Column
NumCols = .Range(.ListBox1.ListFillRange).Columns.Count

.Cells(FirstRow, FirstCol).Resize(, NumCols).Copy .Cells(FirstRow,
TARGET_COL)

LastRow = .Cells(.Rows.Count, TARGET_COL).End(xlUp).Row
With .ListBox1

Me.Range(.ListFillRange).Cells(1,
1).Offset(.ListIndex).Resize(1, NumCols).Copy Me.Cells(LastRow + 1, "AA")
Me.ListBox2.ListFillRange = Me.Cells(1,
TARGET_COL).Resize(LastRow + 1, NumCols).Address
End With
End With
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"steve" wrote in message
...
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




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
Double click item in Listbox to select item and close Listbox GusEvans Excel Programming 3 July 19th 07 12:36 PM
listbox add item Baha Excel Programming 0 December 8th 06 02:37 AM
Add item to listbox, but only if it is not already there. Mark Excel Programming 4 September 2nd 05 10:07 PM
The value of a ListBox Item TK Excel Programming 2 August 20th 04 06:17 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


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