|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码如下
Option Explicit
Sub factor_run()
Dim a, b, c, d, m As Byte, nom As Long, t, DD As Double, sa As Long
Dim matagetb, ppptb, maxage As Variant
Const DB As Byte = 0
Const Survival As Byte = 0
Const Maturity As Byte = 0
Const Div_l As Byte = 0
Const Div_m As Byte = 0
Const Div_h As Byte = 0
t = Timer
Application.ScreenUpdating = False
Sheets("factor").UsedRange.ClearContents '清空factor表里factorb区域的内容
Application.Calculation = xlManual '手动计算
With Worksheets("FACTOR") 'FACTOR工作表的第一行依次赋予相应的字段
.Cells(1, 1) = "BT"
.Cells(1, 2) = "PT"
.Cells(1, 3) = "Age"
.Cells(1, 4) = "Sex"
.Cells(1, 5) = "Duration"
.Cells(1, 6) = "SA"
.Cells(1, 7) = "GP"
.Cells(1, 8) = "DB"
.Cells(1, 9) = "DD"
.Cells(1, 10) = "Survival"
.Cells(1, 11) = "Maturity"
.Cells(1, 12) = "CV"
.Cells(1, 13) = "NP_CV"
.Cells(1, 14) = "Reserve"
.Cells(1, 15) = "NP_Res"
.Cells(1, 16) = "Div_l"
.Cells(1, 17) = "Div_m"
.Cells(1, 18) = "Div_h"
End With
nom = 2 '给变量赋值
matagetb = Array(70, 85, 106) '定义数组变量,保至多少岁,的三个选项
ppptb = Array(5, 10, 15, 20, 30) '定义数组变量,缴费期间数的几种方式
For a = 0 To 2 '定义一个保至多少岁的第一层循环
Range("BT").Value = matagetb(a)
For b = 0 To 4 '建立一个缴费期数的第二层循环
Range("PT") = ppptb(b)
For c = 1 To 2 '建立一个性别属性的第三层循环
Range("Sex") = c
If a = 0 Then '由选择的保至多少岁以及缴费期数,推出最大的投保年龄,此处考虑了保至70周岁,缴费期数为30的特殊的最大投保年龄40
maxage = Array(55, 55, 55, 50, 40)
Else
maxage = Array(55, 55, 55, 55, 55)
End If
For d = 0 To maxage(b) '建立一个,投保年龄从0至最大的投保年龄的第四层循环,每一个缴费期间数,对应一个最大的投保年龄,并将其作为循环的上界
Range("Age") = d
Sheets("Filing").Calculate '依次刷新计算以下几张工作表
Sheets("Premium").Calculate
Sheets("CV").Calculate
Sheets("Reserve").Calculate
m = Worksheets("Filing").Range("C13").Value '保险期间数量 factor表格依对应的保险期间往下
sa = Worksheets("Filing").Range("C15").Value '赋值保额给变量sa
DD = sa '疾病保额(结合具体产品模型)
With Worksheets("factor")
.Cells(nom, 1).Resize(m, 1) = Range("BT").Value '赋值保至多少数
.Cells(nom, 2).Resize(m, 1) = Range("PT").Value '赋值缴费期间数
.Cells(nom, 3).Resize(m, 1) = Range("Age").Value '赋值投保年龄
.Cells(nom, 4).Resize(m, 1) = c '赋值性别
.Cells(nom, 6).Resize(m, 1) = sa '赋值保额
.Cells(nom, 7).Resize(Range("PT"), 1) = Worksheets("Premium").Range("L3").Value '赋值对应缴费期的毛保费
.Cells(nom, 8).Resize(m, 1) = DB '赋值死亡保额
.Cells(nom, 9).Resize(m, 1) = DD '赋值疾病保额
.Cells(nom, 10).Resize(m, 1) = Survival
.Cells(nom, 11).Resize(m, 1) = Maturity '赋值满期给付保额
.Cells(nom, 16).Resize(m, 1) = Div_l
.Cells(nom, 17).Resize(m, 1) = Div_m
.Cells(nom, 18).Resize(m, 1) = Div_h
Worksheets("CV").Range("B11").Resize(m, 1).Copy
.Cells(nom, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False '赋值相应的 DURATION '赋值相应的 DURATION
Worksheets("CV").Range("AQ11").Resize(m, 1).Copy
.Cells(nom, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False '赋值相应的现金价值(final或者其他标志)
Worksheets("CV").Range("AS11").Resize(m, 1).Copy
.Cells(nom, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False '赋值相应的调整后的NP_CV
Worksheets("Reserve").Range("Z11").Resize(m, 1).Copy '赋值偿一代的准备金
.Cells(nom, 14).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
Worksheets("Reserve").Range("AB11").Resize(m, 1).Copy '赋值偿一代的调整后的NP_RES
.Cells(nom, 15).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
nom = nom + m
End With
Next d
Next c
Next b
Next a
Application.ScreenUpdating = True
MsgBox "模型运行时间约为:" & Format(Timer - t, "0.00") & "秒。"
End Sub
|
|