Excel 2000 Visual Basic - Export Contents of ListBox into a worksh

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I developed 2 list boxes and succesfully added items to the first ListBox.
I then selected items from ListBox1 to ListBox2. What is the best way to
place the items from ListBox to into another worksheet within the same
workbook.

Thanks.

Ligaya
 
I am not quite sure what you are trying to do, but this code will spit the
items in a listbox into a worksheet:

Private Sub CommandButton1_Click()
Dim i As Integer
For i = 0 To ListBoxX.ListCount - 1
With ActiveCell
.Value = ListBoxX.List(i)
.Offset(1, 0).Select
End With
Next i
End Sub

You will need to rename ListBoxX according to thae name that you are using.
You also need to identify the Workcheet and Cell address for the ActiveCell
refenence.

Hope this helps

Alasdair Stirling
 
Your question is pretty vague. Assume a multiselect listbox on a userform
or on a worksheet and a commandbutton triggers the action.

Private Sub Commandbutton1_Click()
Dim j as Long, i as long
j = 1
for i = 0 to me.listbox1.Listcount - 1
if me.listbox1.selected(i) then
Worksheets(1).cells(j,1).Value = me.listbox1.List(i)
j = j + 1
End if
Next
End Sub

perhaps the above will give you some ideas.
 
Alasdair Stirling said:
I am not quite sure what you are trying to do, but this code will spit the
items in a listbox into a worksheet:

Private Sub CommandButton1_Click()
Dim i As Integer
For i = 0 To ListBoxX.ListCount - 1
With ActiveCell
.Value = ListBoxX.List(i)
.Offset(1, 0).Select
End With
Next i
End Sub

You will need to rename ListBoxX according to thae name that you are using.
You also need to identify the Workcheet and Cell address for the ActiveCell
refenence.

Hope this helps

Alasdair Stirling

You got what I want to do with the 2nd List Box.

Thanks.

Ligaya
 
Tom Ogilvy said:
Your question is pretty vague. Assume a multiselect listbox on a userform
or on a worksheet and a commandbutton triggers the action.

Private Sub Commandbutton1_Click()
Dim j as Long, i as long
j = 1
for i = 0 to me.listbox1.Listcount - 1
if me.listbox1.selected(i) then
Worksheets(1).cells(j,1).Value = me.listbox1.List(i)
j = j + 1
End if
Next
End Sub

perhaps the above will give you some ideas.
 
Tom Ogilvy said:
Your question is pretty vague. Assume a multiselect listbox on a userform
or on a worksheet and a commandbutton triggers the action.

Private Sub Commandbutton1_Click()
Dim j as Long, i as long
j = 1
for i = 0 to me.listbox1.Listcount - 1
if me.listbox1.selected(i) then
Worksheets(1).cells(j,1).Value = me.listbox1.List(i)
j = j + 1
End if
Next
End Sub

perhaps the above will give you some ideas.
Thanks. I was responding to an OptionButton (same finction in my program
as CommandButton).

Ligaya
 
Well, if you want everything in listbox2 listed in column A, starting in row
1

Private Sub OptionButton1_click()
Dim lbx as MSForms.Listbox
set lbx = me.Listbox2
if me.optionButton1.Value then
with worksheets(1)
.Range("A1").Resize(lbx.listcount,1).Value = _
lbx.List
end with
End if
End sub
 
Tom Ogilvy said:
Well, if you want everything in listbox2 listed in column A, starting in row
1

Private Sub OptionButton1_click()
Dim lbx as MSForms.Listbox
set lbx = me.Listbox2
if me.optionButton1.Value then
with worksheets(1)
.Range("A1").Resize(lbx.listcount,1).Value = _
lbx.List
end with
End if
End sub

Thanks. It worked like a charm. I was dumping the contents of the ListBox
into a range in the worksheet.

Ligaya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top