Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Runtime Error 9 Subscript out of range

  Asked By: Arnold    Date: Aug 25    Category: MS Office    Views: 1047
  

I have a program that creates runtime error 9 subscript
out of range and it drives me crazy. Could someone help with this.
Here is some part of the code. The line tat causes the problem is the
last line.


Option Explicit
Option Base 1

Dim IPD_Old(2) As Single
Dim IPD_Old_Not(2) As Single
Dim FT
Dim Collection
Dim UnusedAccounts() As Single 'Funded Accounts left after death or
disability
Dim sw_EP() As Single 'switchers existing pensioners
Dim nsw_EP() As Single 'non-switchers existing pensioners
Dim sw_NP() As Single
Dim nsw_NP() As Single
Dim sw_NC() As Single
Dim nsw_NC() As Single
Dim Total_sw_NP() As Single
Dim Total_nsw_NP() As Single
Dim Total_sw_EP() As Single
Dim Total_nsw_EP() As Single
Dim Recognized_sw() As Single
Dim Recognized_nsw() As Single
Dim reformedIPDNotional() As Single
Dim reformedIPDPAYG() As Single
Dim ChangeNotional() As Single
Dim ChangeFunded() As Single
Dim Old_NPV_sw
Dim Old_NPV_nsw
Dim Old_NPV_Not
Dim wage_sw
Dim wage_nsw
Dim wage_funded
Dim ConstraintSwPAYG
Dim ConstraintNswPAYG
Dim ConstraintNot
Dim UnConstraintSwPAYG
Dim UnConstraintNswPAYG
Dim ConstraintFunded
Dim AccruedOptions
Dim DataStarts As Integer

Sub ReformOptions()
Dim k As Integer
Dim survival As Single
Dim Division
If Not flags(Aging_done) Then M1_T3_Aging
If Not flags(Benefits_done) Then M3_T3_get_benefits
flags(Options_done) = True
With myinput.Worksheets("Reform")
reform_year = .Range("ReformYear") - yb + 1
Division = .Range("Division")
NotionalPresent = (.CheckBoxes("Notional") = xlOn)
FundedPresent = (.CheckBoxes("Funded") = xlOn)
Collection = Interpolating(.Range("Evasion"), "Evasion")
End With
ReDim sw_EP(firstContrib - 1 To n_a, reform_year - 1 To ny, 2) As
Single
ReDim sw_NP(firstContrib - 1 To n_a, reform_year To ny, 2) As
Single
ReDim sw_NC(firstContrib - 1 To n_a, reform_year To ny, 2) As
Single
ReDim nsw_EP(firstContrib - 1 To n_a, reform_year - 1 To ny, 2)
As Single
ReDim nsw_NP(firstContrib - 1 To n_a, reform_year To ny, 2) As
Single
ReDim nsw_NC(firstContrib - 1 To n_a, reform_year To ny, 2) As
Single
ReDim Total_sw_NP(2, reform_year To ny) As Single
ReDim Total_nsw_NP(2, reform_year To ny) As Single
ReDim Total_sw_EP(2, reform_year To ny) As Single
ReDim Total_nsw_EP(2, reform_year To ny) As Single
ReDim Recognized_sw(firstContrib - 1 To n_a, 2) As Single
ReDim Recognized_nsw(firstContrib - 1 To n_a, 2) As Single
For g = 1 To 2
For a = firstContrib To n_a
For k = 2 + (g - 1) * 11 To 9 + (g - 1) * 11
If a - 2 >= Division(k, 1) And a - 2 <= Division(k, 7) Then
sw_NP(a, reform_year, g) = Division(k, 10)
sw_NC(a, reform_year, g) = Division(k, 10)
nsw_NP(a, reform_year, g) = Division(k, 11)
nsw_NC(a, reform_year, g) = Division(k, 11)
Recognized_sw(a, g) = Division(k, 8)
Recognized_nsw(a, g) = Division(k, 9)
End If
Next k
Next a
For t = reform_year + 1 To ny
sw_NC(firstContrib, t, g) = Division(1 + (g - 1) * 11, 10)
nsw_NC(firstContrib, t, g) = Division(1 + (g - 1) * 11, 11)
For a = firstContrib + 1 To n_a
sw_NC(a, t, g) = sw_NC(a - 1, t - 1, g)
nsw_NC(a, t, g) = nsw_NC(a - 1, t - 1, g)
sw_NP(a, t, g) = sw_NC(a - 1, t - 1, g)
nsw_NP(a, t, g) = nsw_NC(a - 1, t - 1, g)
Next a
Next t
For t = reform_year To ny
Total_sw_NP(g, t) = 0
Total_nsw_NP(g, t) = 0
Total_sw_EP(g, t) = 0
Total_nsw_EP(g, t) = 0
For a = firstContrib To n_a
sw_NP(a, t, g) = sw_NC(a, t, g) * NP(a, t, g)

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Rachael Ferguson     Answered On: Aug 25

Once the error  occurs, go to Debug and determine what the values for the array
indexes are.
Compare these values to the values used in your ReDim statement.
I suspect that you'll find that one of the indexes is either null, or exceeds
the redim values.

that's what the error is saying...

 
Didn't find what you were looking for? Find more on Runtime Error 9 Subscript out of range Or get search suggestion and latest updates.




Tagged: