Hi guys,
i hope you can help me.
I am trying to copy a range of filtered data to a ListBox, but am struggling with the parameters.
- How can I edit this sub to only copy the visible data of my Range ("RecordData");
- Not copy the first row - headers;
- Not copy empty rows in this range?
Sub updateListBox()
Dim ws As Worksheet
Dim rng As Range
Dim i As Long, j As Long, rw As Long
Dim Myarray() As String
'~~> Change your sheetname here
Set ws = Sheets("Sheet1")
'~~> Set you relevant range here
'Set rng = ws.Range("E2:J5")
Set rng = ws.Range("RecordData")
With Me.ListBox1
.Clear
.ColumnHeads = False
.ColumnCount = rng.Columns.Count
ReDim Myarray(rng.Rows.Count, rng.Columns.Count)
rw = 0
For i = 1 To rng.Rows.Count
For j = 0 To rng.Columns.Count
Myarray(rw, j) = rng.Cells(i, j + 1)
Next
rw = rw + 1
Next
.List = Myarray
'~~> Set the widths of the column here. Ex: For 5 Columns
'~~> Change as Applicable
.ColumnWidths = "75;75;75;75;75;75"
.TopIndex = 0
End With
'End Sub
Thank you for all your help!
Bookmarks