I have the following code that loads an array of data into a listbox on a userform.
Is there a way to change the dimensions of the array if the list goes beyond 41 rows? I've tried using Redim MyArray(51,4), but I get an error message stating the array has already been dimensioned. Is there a way to do a variable number of rows in the array? I also tried using soemthing like:
but that gave me an error message too saying I couldn't use variables. Any suggestions?
Code:
Private Sub UserForm_Initialize()
Dim c As Integer
Dim r As Integer
Dim MyArray(41, 4)
ListBox1.ColumnCount = 4
c = 0
r = 0
'Load values MyArray - 4 columns
LR = Range("A65536").End(xlUp).Row
For Each cell In Range("A2:D" & LR).SpecialCells(xlCellTypeVisible)
MyArray(r, c) = cell
c = c + 1
If c = 4 Then
c = 0
r = r + 1
End If
Next cell
'Load ListBox1
ListBox1.List() = MyArray
End Sub
Is there a way to change the dimensions of the array if the list goes beyond 41 rows? I've tried using Redim MyArray(51,4), but I get an error message stating the array has already been dimensioned. Is there a way to do a variable number of rows in the array? I also tried using soemthing like:
Code:
For x = range("A65536").end(xlup).row
Dim MyArray(x, 4)
but that gave me an error message too saying I couldn't use variables. Any suggestions?