Joe Howard
asked on
Remove first column from a 2d array
Is it possible using VBA only (no copying to excel etc.) to remove the first column in both the the first and second dimension?
Sample array
MyArr(1, 1) = "Apple"
MyArr(1, 2) = "Bannana"
MyArr(1, 3) = "Pear"
MyArr(1, 4) = "Orange"
MyArr(1, 5) = "Cherry"
Desired result
MyArr(1, 1) = "Bannana"
MyArr(1, 2) = "Pear"
MyArr(1, 3) = "Orange"
MyArr(1, 4) = "Cherry"
Sample array
MyArr(1, 1) = "Apple"
MyArr(1, 2) = "Bannana"
MyArr(1, 3) = "Pear"
MyArr(1, 4) = "Orange"
MyArr(1, 5) = "Cherry"
Desired result
MyArr(1, 1) = "Bannana"
MyArr(1, 2) = "Pear"
MyArr(1, 3) = "Orange"
MyArr(1, 4) = "Cherry"
And why not simplify
myArr(1) = "Apple"
myArr(2) = "Bannana"
myArr(3) = "Pear"
myArr(4) = "Orange"
myArr(5) = "Cherry"
For i = 1 To UBound(myArr) - 1
myArr(i) = myArr(i + 1)
Next i
ReDim Preserve myArr(UBound(myArr) - 1)
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Rgonzo1971
It cannot be simplified because the array is populated from a range (MyArr = Sheets(1).Range("A1:G56"). Value) which always creates a 2d array.
MyArray may contain several rows, your code won't work in such a case.
It cannot be simplified because the array is populated from a range (MyArr = Sheets(1).Range("A1:G56").
MyArray may contain several rows, your code won't work in such a case.
pls try
Option Base 1
Open in new window
Regards