我正在为预期的差额评估编写一个excel vba代码。
如果我输入条件'“<”,我的sumif和countif函数返回值0 &安培; Var'(风险值 - 数组的百分位数为2.5%),如果我反转该标准(“>”),这些函数会对所有范围内的值进行求和。
我找不到错误,有人可以帮忙吗? 以下是代码的一部分:
Dim RiskHorizon As Integer
RiskHorizon = InputBox("Set the Risk Horizon!", "Risk Horizon", 10)
Dim SigLev As Double
SigLev = InputBox("Set the Significance Level!", "Significance Level", 0.025)
Dim CountDates As Integer
CountDates = Application.CountIf(Sheets("ExpSh").Columns("A"), "<>" & "") - 1
Dim ReturnRange As Range
Set ReturnRange = Sheets("ExpSh").Range("C2:C" & CountDates - RiskHorizon + 1)
Dim Var As Double
Dim ES As Double
Dim Sums As Double
Dim Counts As Double
Var = Application.WorksheetFunction.Percentile(ReturnRange, SigLev)
Sums = Application.WorksheetFunction.SumIf(ReturnRange, "<" & Var)
Counts = Application.WorksheetFunction.CountIf(ReturnRange, "<" & Var)
ES = Sums / Counts
答案 0 :(得分:0)
也许:
Sums = Application.WorksheetFunction.SumIf(ReturnRange, ""<"" & Var)
Counts = Application.WorksheetFunction.CountIf(ReturnRange, ""<"" & Var)