VBA: Redim Preserve Multidimensional Array?

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
I have looked all over, and can't seem to find an answer to my problem.

I have a multidimensional array that has values I want to exclude, but don't understand the Redim function enough to write the code. Can someone please help me?

AF_Vals = (0 to 6, 0 to 1)

VBA Code:
        For lngVal = 0 To UBound(AF_Vals, 1)
            strTest = Left(AF_Vals(lngVal, LBound(AF_Vals, 2)), 6)
            If strTest <> "Resize" And strTest <> "Number" Then Exit For
        Next lngVal

        ReDim Preserve AF_Vals(LBound(AF_Vals, 1) + lngVal To UBound(AF_Vals, 1), 0 To 1)

When I populate data into AF_Vals if a dimension contains either "Resize" or "Number" in the string, I want those removed from the array, and those values are always at the beginning of the array. Is there a way to remove the lower bounds of the array that contain those strings? Thanks in advance.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
With a 2D array you can only change the size of the 2nd dimension when using redim preserve.
 
Upvote 0
You can only change the upper bound of the last dimension of a multidimensional array
 
Upvote 0
Depends to some extent on what you want to do with it.
One option would be to loop through the array & copy the values you want to keep into a new array.
Another option (depending on how you populate the array) is to not put those values into the array to begin with.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top