Error 9 generated by Redim Preserve

Roger Whiteley

New Member
Joined
Jun 11, 2009
Messages
34
I have a number of arrays of controls in my code for a form, and when trying to redimension them to add additional controls I am getting a subscript out of range error when I try to increase the second dimension of a two dimensional array.

The arrays all contain controls which are built up on a form, the number of rows which is dependent on the amount of data for any enquiry

The original declaration is:

Code:
Public gatxtWTE() As Control

Before use the array is redimmed as follows:

Code:
ReDim gatxtWTE(1 To iNO_of_YEARS, colPOSITIONS.Count)

Where iNo_Of Years represents the number of years which is constant for the processing run, and colPOSITIONS.Count is the size of a collection returned from a User Interface Support Layer.

The initial build up of the controls on the form works perfectly, but when I try to add an extra row of data I get the "subscript out of range error" on the highlighted line below.

Code:
    ReDim Preserve galblPOSITIONS(1 To UBound(galblPOSITIONS, 1) + 1)
    ReDim Preserve galblDESCRIPTIONS(1 To UBound(galblDESCRIPTIONS, 1) + 1)
    ReDim Preserve galblWTE(1 To UBound(galblWTE, 1) + 1)
    ReDim Preserve galblNO_OF_EMPLOYEES(1 To UBound(galblNO_OF_EMPLOYEES, 1) + 1)
[B][U]    ReDim Preserve gatxtWTE(1 To iNO_of_YEARS, 1 To UBound(gatxtWTE, 2) + 1)[/U][/B]
    ReDim Preserve maLABELS(1 To UBound(maLABELS, 1) + 4)
    ReDim Preserve maTEXT_BOXES(1 To UBound(maTEXT_BOXES, 1) + iNO_of_YEARS)

The one dimensional arrays expand correctly, at least up to the error.

Has anybody got any ideas?
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Maybe try:

Rich (BB code):
ReDim gatxtWTE(1 To iNO_of_YEARS, 1 To colPOSITIONS.Count)

Without it the second dimension will be zero based.
 

Roger Whiteley

New Member
Joined
Jun 11, 2009
Messages
34
Thanks

Because the first part was working I was looking in the wrong place for my error. All the other first redims for the one dimensional arrays were (1 to etc)

Roger
 

Watch MrExcel Video

Forum statistics

Threads
1,122,518
Messages
5,596,621
Members
414,081
Latest member
Subaru_Steve

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
Top