Re: How to formulate a one-dimensional array from the elements of a two-dimensional one?
Hello. Try with:
PHP Code:
Sub Matrix2()
Const N = 7, M = 7
Dim Z(1 To N, 1 To M), I As Integer, J As Integer, W, R As Long
Rem -----------------\
For I = 1 To N
For J = 1 To M
Z(I, J) = Int(-6 + Rnd * (10 + 6))
Next
Next
Worksheets("Sheet1").Cells(1, 1).Resize(N, M).Value = Z
Rem -----------------\
ReDim W(1 To N * M)
For I = 1 To N
For J = 1 To M
If Z(I, J) > 0 Then
R = 1 + R
W(R) = Z(I, J)
End If
Next
Next
Rem -----------------\
If R > 0 Then Worksheets("Sheet1").Range("A10").Resize(, R) = W
Worksheets("Sheet1").UsedRange.Columns.AutoFit
End Sub
You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.
Bookmarks