嗨,我正在尝试为租车设置一个计算器。你会把你列入汽车类别,租车天数,你是否想预订燃料舱,你要走多少公里,你是否需要冬季轮胎,如果你要去一个特定的目的地,有多少人会在车里。
我的数据-电子表格目前看起来如下:http://i.imgur.com/P2kz6ts.png
因此,例如,如果你想和两个人一起租一辆福特嘉年华( Fiesta ) 2天,那么冬季轮胎和油耗80公里就可以到达目的地2。计算器现在应该选择1到3天的价格,然后乘以2乘以2,为期两天。此外,冬季轮胎的费用将加起来,每天3欧元。然后,它将增加燃料平50-150公里的成本,因为你将旅行80公里。由于您正在前往目的地2,租赁公司愿意给予15欧元的折扣。最后,计算出的成本除以2,因为两个人将租车并平均分摊费用。这个计算应该是这样的:((30*2+(3*2)+13,80)-15)因此最终总成本32,4欧元将显示在一个msgbox中。
现在,我该如何编码,如果租房天数在1-3之间,excel应该取该特定cost的值,并使用它来计算成本。此外,如果你租车超过一个星期,那么价格6-7天将被使用,并根据类别增加额外的天数。
问题解决了,看答案。
发布于 2014-11-19 12:13:54
下面是解决问题的代码:
If rentaldays > 30 Then
Application.Cells(3, 3).Value = "You're trying to rent a Car for more than 30 Days. Please use the longterm program."
price = 0
End If
If rentaldays = 30 Then
monat = (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 7, False))
End If
If rentaldays > 7 Then
zusatz = price + (((rentaldays - 7) * Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 6, False)))
rentaldays = rentaldays - (rentaldays - 7)
End If
If rentaldays = 6 Or rentaldays = 7 Then
woche = (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 5, False))
End If
If rentaldays > 3 And rentaldays <= 5 Then
tage = price + (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 4, False) * rentaldays)
End If
If rentaldays >= 1 And rentaldays <= 3 Then
tage = price + (Application.WorksheetFunction.VLookup(car, Sheets("Data").Range("A:K"), 3, False) * rentaldays)
End If发布于 2014-11-15 18:29:15
你需要让这更容易,而不是“更聪明”
只需增加更多的列!

然后你有3个简单的规则(英语代码)
if days >= 30 then
price = Col K 'lookup for car
days = days - 30
end if
if days > 7 then
price = price + ((days - 7) * Col J) 'lookup for car
days = days - (days - 7)
end if
if days > 0 then
price = price + hlookup( days, C:I .....) 'lookup for car
end ifhttps://stackoverflow.com/questions/26946190
复制相似问题