Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Getting list data into spreadseet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anand - 29 May 2008 07:06 GMT
I have a UserForm in which I have a List Box. The user can add items
to the list box. At the end I have to get all items from the list box
control and transfer them into a spreadsheet column.
Appreciate any help to achieve this.

Thanks,
Anand.
NateBuckley - 29 May 2008 07:40 GMT
Sub ListBoxToCells()
   
   Dim indexTo As Long
   Dim i As Long
   Dim j As Long
   Dim var As Variant
   'Get how many records exist within the listbox and store that into a
variable
   indexTo = ListBox1.ListCount
   'This will hold the List so we can go through it
   var = ListBox1.List
   j = 1
   'The List starts at element 0 (in the array), so we'll start the i
counter there.
   For i = 0 To indexTo - 1
        'Print out to the Cells.
       Sheet1.Cells(j, 1).Value = var(i, 0)
       j = j + 1
   Next i
End Sub

Hope this helps, if you wish for me to go into more detail then I shall, but
it's all fairly straight forward stuff.

> I have a UserForm in which I have a List Box. The user can add items
> to the list box. At the end I have to get all items from the list box
[quoted text clipped - 3 lines]
> Thanks,
> Anand.
NateBuckley - 29 May 2008 07:43 GMT
Sub ListBoxToCells()
   
   Dim indexTo As Long
   Dim i As Long
   Dim j As Long
   Dim var As Variant
   indexTo = ListBox1.ListCount
   var = ListBox1.List
   j = 1
   For i = 0 To indexTo - 1
       Sheet1.Cells(j, 1).Value = var(i, 0)
       j = j + 1
   Next i
End Sub

Heres the code without the comments as they don't stay on the right lines
when I copy and paste it into here, so I wouldn't want it not to work because
something that should be commented, isn't.

> Sub ListBoxToCells()
>    
[quoted text clipped - 27 lines]
> > Thanks,
> > Anand.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.