View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Variant as matrix

Sub Main()
Dim varr as Variant
varr = Range("A1:A4").Value

foo varr
End Sub

Public Function foo(matrix As Variant)
Dim lb1 as Long, lb2 as Long, ub1 as Long, ub2 as Long
Dim numDim as Long, i as long, j as long
If IsArray(matrix) Then
numDim = 1
lb1 = LBound(matrix, 1)
ub1 = UBound(matrix, 1)
On Error Resume Next
lb2 = LBound(matrix, 2)
ub2 = UBound(matrix, 2)
If Err.Number = 0 Then
Err.Clear
numDim = 2
End If
On Error GoTo 0
If numDim = 1 Then
For i = lb1 To ub1
Debug.Print "i= " & matrix(i)
Next
Else
For i = lb1 To ub1
For j = lb2 To ub2
Debug.Print "Matrix(" & i & ", " & j & ")= " & matrix(i, j)
Next
Next
End If
End If
End Function


--
Regards,
Tom Ogilvy

"curious " wrote in message
...
Some relatively easy question:
Suppose I pass a matrix from spreadsheet to VBA as Variant


Code:
--------------------

Public Function foo(matrix As Variant)

End Function

--------------------


How do I get the dimensions of the matrix?
(i.e. what is the equivalent of LBound,UBound for this case)

How do I address the elements of this matrix
(i.e. what is the equivalent of matrix(i,j) for this case)

Thanks a lot,


---
Message posted from http://www.ExcelForum.com/