Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Dim Count, Demand, SalesPrice, LostSales, PathCost, I, J As Integer, Check As Boolean
  2. Dim DestinationName As String, TotalProfit As Double
  3.  
  4.  
  5. Function CalcProfit(DestinationName As String)
  6.  
  7. Count = Range("PathAll").Columns(1).Rows.Count
  8. Demand = Application.WorksheetFunction.VLookup(DestinationName, Range("Dinfo"), 2, False)
  9. SalesPrice = Application.WorksheetFunction.VLookup(DestinationName, Range("Dinfo"), 3, False)
  10. LostSales = Application.WorksheetFunction.VLookup(DestinationName, Range("Dinfo"), 4, False)
  11. I = 1
  12. Check = False
  13.  
  14.  
  15. Do Until Check = True Or I > Count
  16.  
  17. If Range("PathAll").Columns(3).Rows(I) = 1 And Range("PathAll").Columns(2).Rows(I) = DestinationName Then
  18. Check = True
  19. PathCost = Range("PathAll").Columns(5).Rows(I)
  20. End If
  21. I = I + 1
  22. Loop
  23.  
  24. If Check = True Then
  25. CalcProfit = Demand * (SalesPrice - PathCost)
  26.  
  27. Else
  28. CalcProfit = -(Demand * LostSales)
  29. End If
  30. End Function
  31.  
  32.  
  33. Sub EvalRouteProfit()
  34. Count = Range("Dinfo").Rows.Count
  35. For J = 1 To Count
  36. DestinationName = Range("Dinfo").Columns(1).Rows(J)
  37. TotalProfitValue = TotalProfitValue + CalcProfit(DestinationName)
  38. Next
  39.  
  40.  
  41. MsgBox "Your total route profit is " & TotalProfitValue, vbInformation, "Total profit"
  42.  
  43. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement