2016-11-22 32 views
-1

我想知道我們會收取多少存儲空間。我們正在處理的公司正在使用分層定價策略,根據我們存儲設備的天數來收取更多費用。VBA - 如何計算分層值

分級金額是這些:第1-4天= 100美元,第5-8天= 150美元,第9天+ = 200美元。我將需要計算每天的金額。所以,如果出租3天,我需要以100 /天= 300美元計算3天。如果租金爲8天,那麼我需要計算前4天的總價爲400美元+未來4天的150美元= 600美元,總價爲1000美元。

我有一個天數的計數。如何從使用的租用天數中獲得總成本?

+0

4 + 3 = 7不是8不應該總數是1000 4和4? –

+0

如果你有興趣,也可以用公式完成。 –

+1

難道你不能一次存放4天,然後續約?總是100美元,那麼你會省下一些錢。 :) –

回答

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 
+0

如果這個答案幫助你,請考慮[接受它](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。接受答案獎勵貢獻者,並幫助他人找到工作解決方案。 –

+0

你是對的。感謝您仔細檢查我的結果。我已經更新了這個問題。 –