Redim Preserve - strange Subscript out of Range case

n3olcsatok

New Member
Joined
Jun 7, 2011
Messages
5
Hi All!

I was trying to use a dynamic, 2 dimensional array. I know full well that only the last dimension can be sized, so I used the following code:

Code:
ReDim pFields(1 To 2, 1)
pExtent = 1
Do While Not IsEmpty(vTable.Cells(pExtent, 1))
   ReDim Preserve pFields(1 To 2, 1 To pExtent)
   'other stuff
   pExtent = pExtent + 1
Loop

The strange thing is, I get a Subscript out of range error upon first execution at the ReDim Preserve, yet in another bunch of code this worked perfectly. Do you have any ideas what may have gone wrong?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Declare the array as Dim pFields() to start with. Any good?
 
Upvote 0
First redim should be:
Rich (BB code):
ReDim pFields(1 To 2, 1 To 1)
 
Upvote 0
All depends on Option Base directive. If you have 0 or this directive is omitted, then your second dimension is "0 To 1".
 
Upvote 0
Ah forgot to add, pFields and pExtent are private elements of a class:

Code:
Private pFields() As String
Private pExtent As Long

Code is in a function in the same class.
That's why this whole thing seems strange.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

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