I need a matrix that I do not know 4x4 or 5x5. It changes case by case.
So how can I creat a matrix?
I need a matrix that I do not know 4x4 or 5x5. It changes case by case.
So how can I creat a matrix?
Sub Test() Dim vMatrix() Const x As Long = 4 Const y As Long = 4 vMatrix = Range("A1:C3") 'ReDim vMatrix(1 To x, 1 To y) ReDim Preserve vMatrix(1 To x, 1 To y) End Sub
Regards, TMS
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
reads in a fixed worksheet rangevMatrix = Range("A1:C3")
would resize the matrix BUT destroy the contentsReDim vMatrix(1 To x, 1 To y)
would resize the matrix but retain (preserve) the contentsReDim Preserve vMatrix(1 To x, 1 To y)
I wrote them because they are examples of resizing an array. I do not know what you will be doing or how you will be doing it hence some variations on a theme.
Regards, TMS
One more question,
Why it is not working? I cannot appoint variable to matrixDim matrix() For i = 2 To 10000 If Cells(i, "C").Value = main_part Then matrix= Cells(i, "A").Value End If Next i
Where is main_part defined? What does it contain?
Option Explicit Sub Test2() Dim matrix(), i As Long Const main_part As String = "Test" ReDim matrix(1 To 10000) 'For i = 2 To 10000 For i = 2 To 30 ' for testin If Cells(i, "C").Value = main_part Then matrix(i) = Cells(i, "A").Value Debug.Print Range("A" & i); Range("C" & i); matrix(i) End If Next i End Sub
Regards, TMS
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks