Excel Records


Public Function CalcMoney(carType As Range, timeType As Range, carItems As Range, timeItems As Range, timeValue As Range, others As Range)
Dim temp
Dim unitValue
Dim timeTemp

'先匹配出車型的列index
temp = Application.Match(carType, carItems, 0)

'匹配出車型所對應的機油、機油格數據
unitValue = Application.Index(others, 0, temp + 1)

timeTemp = Application.Match(timeType, timeItems, 0)

'計算總結果
CalcMoney = Application.Sum(unitValue) + Application.Index(timeValue, timeTemp, temp)

'CalcMoney = SUM(INDEX(C5:AF6,0,MATCH($A$22,C3:AF3,0)+1))+INDEX(C18:AF21,MATCH($B$22,$B$18:$B$21,0),MATCH($A$22,C3:AF3,0))
End Function

Sub calc()
Dim result
Dim carItems()
Dim timeItems()
Dim timeValue()
Dim others()
Dim carType
Dim timeType

timeType = Range("$B$22")
carType = Range("$A$22")
carItems = Range("C3:AF3")
timeItems = Range("$B$18:$B$21")
timeValue = Range("C18:AF21")
others = Range("C5:AF6")

result = CalcMoney(carType, timeType, carItems, timeItems, timeValue, others)

MsgBox result
End Sub
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章