Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default comman button on form to transfer items in listbox to a sheet

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default comman button on form to transfer items in listbox to a sheet

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default comman button on form to transfer items in listbox to a sheet

Can the Add item be a range? In one list box I have 1200 employees that can
be possibly selected.

"Dave Peterson" wrote:

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default comman button on form to transfer items in listbox to a sheet

You can use .additem to add the value from cells in a worksheet.

But you have more choices, too. You could use the .rowsource property and just
tell the listbox where to get the info:

Option Explicit
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.RowSource = myRng.Address(external:=True)
.ColumnCount = myRng.Columns.Count
.ColumnHeads = True
End With
End Sub



gbpg wrote:

Can the Add item be a range? In one list box I have 1200 employees that can
be possibly selected.

"Dave Peterson" wrote:

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default comman button on form to transfer items in listbox to a sheet

I am sorry I actually meant the other way around - My list list does get the
names from a sheet. I want to save the info that goes from the listbox one to
listbox 2 (which works) to cells on a sheet.

Listbox one---Listbox two-----sheet cells by a range (instead of adding
all of the cells indivually). The idea is that the cells with the multiple
selection could be used elsewhere after the bookcloses.



"Dave Peterson" wrote:

You can use .additem to add the value from cells in a worksheet.

But you have more choices, too. You could use the .rowsource property and just
tell the listbox where to get the info:

Option Explicit
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.RowSource = myRng.Address(external:=True)
.ColumnCount = myRng.Columns.Count
.ColumnHeads = True
End With
End Sub



gbpg wrote:

Can the Add item be a range? In one list box I have 1200 employees that can
be possibly selected.

"Dave Peterson" wrote:

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default comman button on form to transfer items in listbox to a sheet

If you're using a listbox where you allow multiselections, then you're going to
have to loop through the selected items--like in that first suggestion.

If you just wanted to put the list into a worksheet range:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("b2")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, .ColumnCount).Value = .List
End With
End Sub

I

gbpg wrote:

I am sorry I actually meant the other way around - My list list does get the
names from a sheet. I want to save the info that goes from the listbox one to
listbox 2 (which works) to cells on a sheet.

Listbox one---Listbox two-----sheet cells by a range (instead of adding
all of the cells indivually). The idea is that the cells with the multiple
selection could be used elsewhere after the bookcloses.

"Dave Peterson" wrote:

You can use .additem to add the value from cells in a worksheet.

But you have more choices, too. You could use the .rowsource property and just
tell the listbox where to get the info:

Option Explicit
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.RowSource = myRng.Address(external:=True)
.ColumnCount = myRng.Columns.Count
.ColumnHeads = True
End With
End Sub



gbpg wrote:

Can the Add item be a range? In one list box I have 1200 employees that can
be possibly selected.

"Dave Peterson" wrote:

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default comman button on form to transfer items in listbox to a sheet

thanks Dave, I will try and see if I can get that to work..
Cheers

"Dave Peterson" wrote:

If you're using a listbox where you allow multiselections, then you're going to
have to loop through the selected items--like in that first suggestion.

If you just wanted to put the list into a worksheet range:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("b2")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, .ColumnCount).Value = .List
End With
End Sub

I

gbpg wrote:

I am sorry I actually meant the other way around - My list list does get the
names from a sheet. I want to save the info that goes from the listbox one to
listbox 2 (which works) to cells on a sheet.

Listbox one---Listbox two-----sheet cells by a range (instead of adding
all of the cells indivually). The idea is that the cells with the multiple
selection could be used elsewhere after the bookcloses.

"Dave Peterson" wrote:

You can use .additem to add the value from cells in a worksheet.

But you have more choices, too. You could use the .rowsource property and just
tell the listbox where to get the info:

Option Explicit
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.RowSource = myRng.Address(external:=True)
.ColumnCount = myRng.Columns.Count
.ColumnHeads = True
End With
End Sub



gbpg wrote:

Can the Add item be a range? In one list box I have 1200 employees that can
be possibly selected.

"Dave Peterson" wrote:

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default comman button on form to transfer items in listbox to a sheet

thanks Dave, I got it to work and I think I can actually use this again,
although a generalist can be as dangerous as helpful to himself. I am on to
more now in my mad scheme....

Happy Easter.

"gbpg" wrote:

thanks Dave, I will try and see if I can get that to work..
Cheers

"Dave Peterson" wrote:

If you're using a listbox where you allow multiselections, then you're going to
have to loop through the selected items--like in that first suggestion.

If you just wanted to put the list into a worksheet range:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("b2")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, .ColumnCount).Value = .List
End With
End Sub

I

gbpg wrote:

I am sorry I actually meant the other way around - My list list does get the
names from a sheet. I want to save the info that goes from the listbox one to
listbox 2 (which works) to cells on a sheet.

Listbox one---Listbox two-----sheet cells by a range (instead of adding
all of the cells indivually). The idea is that the cells with the multiple
selection could be used elsewhere after the bookcloses.

"Dave Peterson" wrote:

You can use .additem to add the value from cells in a worksheet.

But you have more choices, too. You could use the .rowsource property and just
tell the listbox where to get the info:

Option Explicit
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.RowSource = myRng.Address(external:=True)
.ColumnCount = myRng.Columns.Count
.ColumnHeads = True
End With
End Sub



gbpg wrote:

Can the Add item be a range? In one list box I have 1200 employees that can
be possibly selected.

"Dave Peterson" wrote:

Maybe you could use something like:

Option Explicit
Private Sub CommandButton1_Click()
Dim DestCell As Range
Dim iCtr As Long

With Worksheets("sheet1")
Set DestCell = .Range("A1")
End With

With Me.ListBox1
DestCell.Resize(.ListCount, 1).ClearContents

For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) Then
DestCell.Value = .List(iCtr)
Set DestCell = DestCell.Offset(1, 0)
End If
Next iCtr
End With
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
.AddItem "a"
.AddItem "b"
.AddItem "c"
.AddItem "d"
.AddItem "e"
End With
End Sub


gbpg wrote:

I have form that has a number of list boxes that use command buttons to
transfer items from one list box to another, I want to save the items to a
sheet with a command button. Can do this with a text box but not with a list
box. Can some one give an example?

--

Dave Peterson


--

Dave Peterson


--

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
Comman Button Brenda New Users to Excel 6 October 14th 08 05:33 AM
Transfer ListBox items to a range AD108 Excel Programming 2 September 10th 06 01:49 PM
Auto filter through the Comman Button irsath Excel Worksheet Functions 2 July 3rd 06 01:04 PM
Adding items to a spreadsheet from a user form listbox aet-inc[_4_] Excel Programming 1 December 3rd 03 05:13 AM
Transfer multiple columns items form listbox to range Rolo[_3_] Excel Programming 3 November 15th 03 06:50 PM


All times are GMT +1. The time now is 01:07 AM.

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"