I am using an userform with a listbox and I want to export the filtered listbox contents into an excel file.
This code loads the DataBodyRange.Value into my listbox. I then filter it using the following code:
1. Where should I start to export the filtered listbox to an excel file?
2. How can I edit things in the array? Or should I edit the databodyrange and then reload the array?
Code:
myarray = Sheet61.ListObjects("Data").DataBodyRange.Value
With ListBox1
.List = myarray
.ColumnCount = 25
.ColumnHeads = False
End With
This code loads the DataBodyRange.Value into my listbox. I then filter it using the following code:
Code:
Private Sub TextBox1_Change()Application.ScreenUpdating = False
Dim endarr(), ListEndRow As Long, lrows As Long, i As Long, j As Long, k As Long
If TextBox1.Text = vbNullString Then ListBox1.List = myarray: Exit Sub
ListEndRow = 1
With Sheet61
lrows = .ListObjects("Data").DataBodyRange.Rows.Count
ReDim endarr(1 To lrows, 1 To 21)
For i = 1 To UBound(myarray)
If Left(LCase(myarray(i, 5)), LCase(Len(TextBox1.Text))) = LCase(TextBox1.Text) Then
For j = 1 To 20
endarr(ListEndRow, j) = myarray(i, j)
Next
ListEndRow = ListEndRow + 1
End If
Next
End With
ListBox1.List = endarr
Me.TextBox1.BackColor = RGB(231, 125, 0)
Application.ScreenUpdating = True
End Sub
1. Where should I start to export the filtered listbox to an excel file?
2. How can I edit things in the array? Or should I edit the databodyrange and then reload the array?