View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Transfering Data from ListBox to Worksheet

Option Explicit

Sub TransferToSheet()
Dim i&, n&, vaItems As Variant

With Me.ListBox1
ReDim vaItems(1 To .ListCount)

For i = 0 To .ListCount - 1
If .Selected(i) Then
n = n + 1
vaItems(n) = .List(i)
End If
Next
End With

'remove the unused items from the array
ReDim Preserve vaItems(1 To n)
'if we're going to store this in a "vertical" range,
'we must use transpose
Range("a1").Resize(n, 1) = Application.Transpose(vaItems)

End Sub

Private Sub UserForm_Click()
TransferToSheet
End Sub


Private Sub UserForm_Initialize()
add some dummy data
Me.ListBox1.MultiSelect = fmMultiSelectExtended
Dim i&
For i = 0 To 99
Me.ListBox1.AddItem "item " & Format(i, "00")
Next

End Sub



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam

?B?Um9uYm8=?= wrote in message
:

I have created a UserForm with a ListBox. If the user clicks on the
macro button €śAdd to List€ť the ListBox is opened with all of the
options, and now you can simply click on the item(s) you want to add
to the worksheet sheet in column B, starting at B8. I have it all set
up to the point of transferring the data (or item(s) selected) to the
worksheet. i.e The ListBox of "item options" comes up perfectly, I
can select (highlight) the items I want to add to the list on the
worksheet€¦ but I dont know how to transfer the selected
(highlighted) items to the worksheet in the next open cell, starting
with B8 by clicking on the OK command button.

Any help with the code needed for the OK button to transfer the data
would be greatly appreciated.

P.S. Thanks to Dick Kusleika for the previous suggestions, but
neither solved my problem.