下面是Excel VBA 一段程序,目的是要改变一些变量 withdraw, death_a_rate, comm_rate, invest_a_rate, fee, ex_rate这六个然后把改变后想要的数据结果 Worksheets("利润测试").Cells(10, l(这都是L)).Value 这里的 生成一张9行14列的表格。
但是到黄色那句就显示下标越界了!请问问题在哪怎么改啊!我刚学VBA。。
对能解决的感激涕零!
代码如下:
Dim age, f, c, i, e, w, d, h, l As Integer
Dim withdraw, death_a_rate, comm_rate, invest_a_rate, fee, ex_rate, result, database As Variant
withdraw = Array(1.5, 1.25, 0.75)
death_a_rate = Array(1.1, 0.9, 0.8)
comm_rate = Array(1.1, 1.05, 0.95)
invest_a_rate = Array(0.055, 0.045, 0.04)
fee = Array(1.5, 1.25, 0.75)
ex_rate = Array(1.2, 1.1, 0.9)
Range("scer").ClearContents
result = Range("scer").Value
For l(这是L) = 1 To 14
h = 2
For i = 0 To 2
Range("invest_rate_adjust").Value = invest_a_rate(i)
h = h + i
result(h, l) = Worksheets("利润测试").Cells(10, l).Value
Range("invest_rate_adjust").Value = 0
Next i
h = h + 1
For w = 0 To 2
Range("withdraw_adjust").Value = withdraw(w)
h = h + w
result(h, l) = Worksheets("利润测试").Cells(10, l).Value
Range("withdraw_adjust").Value = 1
Next w
h = h + 1
For d = 0 To 2
Range("death_rate_adjust").Value = death_a_rate(d)
h = h + d
result(h, l) = Worksheets("利润测试").Cells(10, l).Value
Range("death_rate_adjust").Value = 1
Next d
h = h + 1
For e = 0 To 2
Range("ex_adjust").Value = ex_rate(e)
h = h + e
result(h, l) = Worksheets("利润测试").Cells(10, l).Value
Range("ex_adjust").Value = 1
Next e
h = h + 1
For f = 0 To 2
Range("ave_prem_adjust").Value = fee(f)
h = h + f
result(h, l) = Worksheets("利润测试").Cells(10, l).Value
Range("ave_prem_adjust").Value = 1
Next f
h = h + 1
For c = 0 To 2
Range("comm_adjust").Value = comm_rate(c)
h = h + c
result(h, l) = Worksheets("利润测试").Cells(10, l).Value
Range("ave_prem_adjust").Value = 1
Next c
h = h + 1
Next l
Range("scer").Value = result