Vinci2504
New Member
- Joined
- Jan 13, 2020
- Messages
- 7
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
- Mobile
- Web
Hi Eweryone,
It my first post on the forum, but I am reading forum from long time. Is nice to have a that good kind of support. Always trying solve problems myself, but I have the problem with 3D array.
I am preparing the app to remove rows from 3D array in which conditions is fulfill.
I have the error from app in line: NewArray(col, rowNew, 0) = BaseArray(col, row, 0) ' Error: Subscript out of range
Is someone who can support in this case?
The table is looks like:
The code is:
It my first post on the forum, but I am reading forum from long time. Is nice to have a that good kind of support. Always trying solve problems myself, but I have the problem with 3D array.
I am preparing the app to remove rows from 3D array in which conditions is fulfill.
I have the error from app in line: NewArray(col, rowNew, 0) = BaseArray(col, row, 0) ' Error: Subscript out of range
Is someone who can support in this case?
The table is looks like:
Row/Col | 11 | 12 | 13 | .... | 21 |
1 | 1 / RND | 1 / RND | 1 / RND | 1 / RND | 1 / RND |
2 | 2 / RND | 2 / RND | 2 / RND | 2 / RND | 2 / RND |
.... | ... / RND | ... / RND | ... / RND | ... / RND | ... / RND |
10 | 10 / RND | 10 / RND | 10 / RND | 10 / RND | 10 / RND |
The code is:
VBA Code:
'App for preparation of 3D Array
'Column = 11:21
'Row = 1:10
'dimension 0: Row
'Dimension 1: Int(50 * Rnd) + 1
Sub ArrayTestRemove2()
Dim BaseArray(11 To 21, 1 To 10, 1) ' Declare array variables.
Dim NewArray As Variant
'Dim i, j, j1, k As Long
Dim col, row, rowNew As Long
'--- Print
Debug.Print "Minimum number of Row: "; LBound(BaseArray, 2) 'Minimum number of Row
Debug.Print "Maximum number of Row: "; UBound(BaseArray, 2) 'Maximum number of Row
Debug.Print "Minimum number of Col: "; LBound(BaseArray, 1) 'Minimum number of Row
Debug.Print "Maximum number of Col: "; UBound(BaseArray, 1) 'Maximum number of Row
'--- Prepare Array in two dimensions (col, row, page)
For col = LBound(BaseArray, 1) To UBound(BaseArray, 1)
For row = LBound(BaseArray, 2) To UBound(BaseArray, 2)
BaseArray(col, row, 0) = row
BaseArray(col, row, 1) = row & "." & Int(50 * Rnd) + 1
Next row
Next col
'--- print Array
For row = LBound(BaseArray, 2) To UBound(BaseArray, 2)
For col = LBound(BaseArray, 1) To UBound(BaseArray, 1)
Debug.Print col; row; "|"; BaseArray(col, row, 0); BaseArray(col, row, 1)
'Debug.Print MyArray(i, j, 1)
Next col
Next row
'--- Print
Debug.Print "Array(col=1, row=10, page=0): "; BaseArray(11, 10, 0)
'--- Remove rows when Value in Column 11 > 9 in both dimensions
ReDim NewArray(LBound(BaseArray, 2) To UBound(BaseArray, 2))
rowNew = 1
For row = 1 To UBound(BaseArray, 2)
For col = LBound(BaseArray, 1) To UBound(BaseArray, 1)
If BaseArray(11, row, 0) <> 9 Then
rowNew = rowNew + 1
NewArray(col, rowNew, 0) = BaseArray(col, row, 0) ' Error: Subscript out of range
NewArray(col, rowNew, 1) = BaseArray(col, row, 1)
End If
Next col
Next row
ReDim Preserve NewArray(LBound(BaseArray, 2) To rowNew)
'--- Finish
Debug.Print "Done"
End Sub