VBA - 如何计算分层值

时间:2016-11-22 15:13:55

标签: vba excel-vba excel

我想知道我们将收取多少存储空间。我们正在处理的公司正在使用分层定价策略,根据我们存储设备的天数收取更多费用。

分层金额为:第1-4天= 100美元,第5-8天= 150美元,第9天+ = 200美元。我需要计算每天的金额。因此,如果出租3天,我将需要计算3天100 /天= 300美元。如果租期为8天,那么我需要计算前4天的总价400美元+接下来的4天150每次= 600,总计1000美元。

我有天数。如何从使用的租赁天数中获得总费用?

1 个答案:

答案 0 :(得分:1)

以下将提示输入,并返回带有答案的消息框。另外,你说8天应该返回850,但你的意思是1000?如果不让我知道,我会更新。

    Sub calculateCost()

    Dim intDays As Variant
    Dim dblCost As Double
    intDays = InputBox("Please type in number of days")

    If Not IsNumeric(intDays) Then
        MsgBox "Please type only numbers"
        Exit Sub
    End If

    Select Case intDays
        Case 1, 2, 3, 4
            dblCost = intDays * 100
        Case 5, 6, 7, 8
            dblCost = 400 + (intDays - 4) * 150
        Case Is > 8
            dblCost = 1000 + (intDays - 8) * 200
        Case Else
            dblCost = 0
    End Select

        MsgBox "Total cost is " & dblCost
End Sub