Reputation: 89
I am trying to export my userform listbox contents to a new workbook.
I am getting the error as I commented in the code.
Private Sub ExportListBoxContents_Click()
Dim xlApp As Excel.Application
Dim xlsh As Excel.Worksheet
Dim i As Integer
Dim j As Integer
Set xlApp = New Excel.Application
xlApp.Workbooks.Add
Set xlsh = xlApp.Workbooks(1).Worksheets(1)
For j = 1 To ListBox1.ListCount
For i = 0 To ListBox1.ColumnCount
xlsh.Cells(j, i).Value = ListBox1.List(j - 1, i) '<----Object defined error
Next i
Next j
xlApp.Visible = True
Set xlsh = Nothing
Set xlApp = Nothing
End Sub
Upvotes: 0
Views: 169
Reputation: 89
Okay I have managed to solve it after so many hours and searching.
All I had to do is amend the line from this:
xlsh.Cells(j, i).Value = ListBox1.List(j - 1, i)
To this:
xlsh.Cells(j , i).Value = ListBox1.Column(j - 1, i - 1)
Upvotes: 1