Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用VBA Excel计算折旧余额法_Vba - Fatal编程技术网

如何用VBA Excel计算折旧余额法

如何用VBA Excel计算折旧余额法,vba,Vba,我的代码如下: Function Depreciation(pCost As Currency, Age As Double) Dim cValue As Currency Dim Dep As Double Select Case Age Case Is < 1 Dep = pCost cValue = pCost - Dep Depreciation = cValue

我的代码如下:

Function Depreciation(pCost As Currency, Age As Double)

    Dim cValue As Currency
    Dim Dep As Double

    Select Case Age
        Case Is < 1
            Dep = pCost
            cValue = pCost - Dep
            Depreciation = cValue

        Case Is < 2
            Dim cValue1 As Currency
            Depreciation = cValue * 0.25
            cValue1 = cValue - Depreciation
            Depreciation = cValue1

        Case Is < 3
            Dim cValue2 As Currency
            Depreciation = cValue1 * 0.25
            cValue2 = cValue1 - Depreciation
            Depreciation = cValue2
    End Select

End Function
功能折旧(成本为货币,年限为双倍)
作为货币的价值
双精度差
选择病例年龄
病例<1例
Dep=pCost
C值=成本-折旧
折旧=价值
病例<2例
将C值1作为货币
折旧=C价值*0.25
C价值1=C价值-折旧
折旧=C价值1
病例<3例
将C值2作为货币
折旧=C价值1*0.25
C价值2=C价值1-折旧
折旧=C价值2
结束选择
端函数

假设您希望在定价后获得该金额,请尝试以下操作:

Option Explicit

Function Depreciation(pCost As Currency, Age As Double)
    Const DepreciationRate As Currency = 0.25
    Dim cValue As Currency, i As Double

    cValue = pCost
    i = Age
    Do Until i < 1
        cValue = cValue * (1 - DepreciationRate)
        'Debug.Print Age - i + 1, cValue ' Uncomment to see value of wach year
        i = i - 1
    Loop
    Depreciation = cValue
End Function
选项显式
功能折旧(成本为货币,年限为双倍)
以货币表示的常数折旧率=0.25
将C值作为货币,将i作为双倍
C值=成本
i=年龄
直到我<1为止
C价值=C价值*(1-折旧率)
“Debug.Print Age-i+1,cValue”取消注释以查看wach year的值
i=i-1
环
折旧=价值
端函数