# Exporting Listbox to excel

**URL:** <https://forum.xojo.com/t/exporting-listbox-to-excel/44422>\
**Category:** Getting Started\
**Created:** [July 20, 2018, 4:32am UTC](https://forum.xojo.com/t/exporting-listbox-to-excel/44422 "2018-07-20T04:32:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arief\_Sarjono](https://forum.xojo.com/user_avatar/forum.xojo.com/arief_sarjono/32/692_2.png) [@Arief\_Sarjono](https://forum.xojo.com/u/Arief_Sarjono)\
**Post date:** [July 20, 2018, 4:32am UTC](https://forum.xojo.com/t/exporting-listbox-to-excel/44422/1 "2018-07-20T04:32:37Z")

</div>

Hi,

I have read mr. dakin’s book about excel in xojo. I am trying to modified some data, because the samples is generate data randomly.

[code]Dim excel as new ExcelApplication  
excel.Visible = true  
excel.Workbooks.Add  
Dim i as integer  
Dim s as string  
Dim r as ExcelRange  
Dim StartTime as Double = Microseconds

'//Create Data  
'For i = 1 to 16000  
's = s + “A” + cstr(i) + “B” + EndOfLine.Windows  
'Next

//Create Data  
For i = 0 to Listbox1.ListCount-1  
s = Listbox1.cell(i,0)  
Next

//Copy to clipboard  
Dim c as new Clipboard  
c.SetText(s)  
c.Close

//Paste from Clipboard to Excel  
r = excel.Range(“A1:A16000”)  
r.Select\_  
excel.ActiveSheet.PasteSpecial(“Text”,false,false)  
//MsgBox “16,000 datapoints added to excel”  
Dim ThisTime as Double = Microseconds  
MsgBox CStr((ThisTime-StartTime)/1000000) + " Seconds"  
//Show elapsed time[/code]

I love the way its exporting the data, very fast. so I want to do it using clipboard method. I dont know why, its not running an no error showing.

any help ?

thanks  
Regards,  
Arief

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [July 20, 2018, 5:09am UTC](https://forum.xojo.com/t/exporting-listbox-to-excel/44422/2 "2018-07-20T05:09:17Z")

</div>

for starters… “s” contains only the value in your last row of the listbox, so if that one is “empty” you get nothing

---

<div class="post-metadata">

**Author:** ![Sascha\_S](https://forum.xojo.com/user_avatar/forum.xojo.com/sascha_s/32/22328_2.png) [@Sascha\_S](https://forum.xojo.com/u/Sascha_S)\
**Post date:** [July 20, 2018, 5:41am UTC](https://forum.xojo.com/t/exporting-listbox-to-excel/44422/3 "2018-07-20T05:41:07Z")

</div>

As Dave wrote.

You are replacing the content of s in each iteration. Try:

[quote=397046:@Arief Sarjono] For i = 0 to Listbox1.ListCount-1  
s = s + EndOfLine + Listbox1.cell(i,0)  
Next  
[/quote]

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:17pm UTC](https://forum.xojo.com/t/exporting-listbox-to-excel/44422/4 "2020-10-29T19:17:30Z")

</div>


