Hello Mrexcel community,
How does VBA access columns and rows in a dynamic array/matrix? Say for instance i use the array:
Normally, ROWS(RANDARRAY(...)) = n_rows and COLUMNS(RANDARRAY(...))=n_columns, but when using VBA, there doesnt seem to be the same
logic to handling the rows and columns, when the array does not exist "typed out" within the spreadsheet.
If i attempt to call this function as =COLMAX(RANDARRAY(3,5)) it returns an error, as #NAME?. The same problem occurs with the function:
So how do i instead access rows and columns of a dynamic array using VBA, if not by using .Columns and .Rows? It should be noted that i am still fairly new to using VBA in excel.
Thank you for any and all insight on how to work around this issue!
How does VBA access columns and rows in a dynamic array/matrix? Say for instance i use the array:
Excel Formula:
=RANDARRAY(5 rows , 4 columns)
Normally, ROWS(RANDARRAY(...)) = n_rows and COLUMNS(RANDARRAY(...))=n_columns, but when using VBA, there doesnt seem to be the same
logic to handling the rows and columns, when the array does not exist "typed out" within the spreadsheet.
VBA Code:
Function COLMAX(Data_Range As Range) As Variant
Dim TempArray() As Double, i As Long
If Data_Range Is Nothing Then Exit Function
With Data_Range
ReDim TempArray(1 To .Columns.Count)
For i = 1 To .Columns.Count
TempArray(i) = Application.Max(.Columns(i))
Next
End With
COLMAX = TempArray
End Function
If i attempt to call this function as =COLMAX(RANDARRAY(3,5)) it returns an error, as #NAME?. The same problem occurs with the function:
VBA Code:
Function COLCOUNT(Data_Range As Range) As Variant
COLCOUNT= Data_Range.Columns.Count
End Function
So how do i instead access rows and columns of a dynamic array using VBA, if not by using .Columns and .Rows? It should be noted that i am still fairly new to using VBA in excel.
Thank you for any and all insight on how to work around this issue!