Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. ============================================================================================
  2.  
  3. Function FindMax(valueArray, nameArray) As String
  4.  
  5. Dim maxVal As Integer
  6. Dim maxValIndex As Integer
  7. maxVal = 0
  8. maxValIndex = 0
  9.  
  10. Dim i As Integer
  11.  
  12. For i = LBound(valueArray) To UBound(valueArray)
  13. If valueArray(i) > maxVal Then
  14. maxVal = valueArray(i)
  15. maxValIndex = i
  16. End If
  17. Next i
  18.  
  19. FindMax = nameArray(maxValIndex)
  20.  
  21. End Function
  22.  
  23. ============================================================================================
  24.  
  25. Function FindMaxRange(valueRng As Range, nameRng As Range) As String
  26.  
  27. Dim maxVal As Integer
  28. Dim maxIndex As Integer
  29.  
  30. maxVal = 0
  31. maxIndex = 0
  32.  
  33. Dim i As Integer
  34.  
  35. For i = 1 To valueRng.Count
  36. If valueRng.Cells(i) > maxVal Then
  37. maxVal = valueRng.Cells(i)
  38. maxIndex = i
  39. End If
  40. Next i
  41.  
  42. FindMaxRange = nameRng.Cells(maxIndex)
  43.  
  44. End Function
  45.  
  46. ============================================================================================
  47.  
  48. Function printMovieData(title As String, arrayTopic, arrayOther)
  49.  
  50. Debug.Print ("*****************" & title & "***************")
  51.  
  52. Dim i As Integer
  53.  
  54. For i = LBound(arrayTopic) To UBound(arrayTopic)
  55. Debug.Print (arrayTopic(i) & " : " & arrayOther(i))
  56. Next i
  57.  
  58. Debug.Print ("**********************************************")
  59.  
  60. End Function
  61.  
  62. ============================================================================================
  63.  
  64. Function MovieWithLargestRental(rngMovie As Range, rngMovieRental As Range) As String
  65.  
  66. MovieWithLargestRental = FindMaxRange(rngMovieRental, rngMovie)
  67.  
  68. End Function
  69.  
  70. ============================================================================================
  71.  
  72. Function MostExpensiveMovieToMake(rngMovie As Range, rngMovieProduction As Range) As String
  73.  
  74. MostExpensiveMovieToMake = FindMaxRange(rngMovieProduction, rngMovie)
  75.  
  76. End Function
  77.  
  78. ============================================================================================
  79.  
  80. Function FindMovieProfit(nameRng As Range, productionCostRng As Range, boxOfficeRng As Range) As String
  81.  
  82. Dim profit As Double
  83. Dim maxProfit As Double
  84. Dim maxProfitIndex As Integer
  85. Dim boxEarnings As Integer
  86. Dim prodCost As Integer
  87.  
  88. maxProfit = 0
  89. maxProfitIndex = 0
  90.  
  91.  
  92. Dim i As Integer
  93. For i = 1 To nameRng.Count
  94.  
  95. boxEarnings = boxOfficeRng.Cells(i)
  96. prodCost = productionCostRng.Cells(i)
  97.  
  98. profit = (boxEarnings - prodCost) / prodCost * 100
  99.  
  100. If profit > maxProfit Then
  101. maxProfit = profit
  102. maxProfitIndex = i
  103. End If
  104.  
  105. Next i
  106.  
  107. FindMovieProfit = nameRng(maxProfitIndex)
  108.  
  109. End Function
  110.  
  111.  
  112. ============================================================================================
  113.  
  114.  
  115. Function FindMovieProfitByGenre(nameRng As Range, productionCostRng As Range, boxOfficeRng As Range, genreRng As Range, genre As String) As String
  116.  
  117. Dim profit As Double
  118. Dim maxProfit As Double
  119. Dim maxProfitIndex As Integer
  120. Dim boxEarnings As Integer
  121. Dim prodCost As Integer
  122.  
  123. maxProfit = 0
  124. maxProfitIndex = 0
  125.  
  126.  
  127. Dim i As Integer
  128. For i = 1 To nameRng.Count
  129.  
  130. If StrComp(genreRng.Cells(i), genre, vbTextCompare) = 0 Then
  131. boxEarnings = boxOfficeRng.Cells(i)
  132. prodCost = productionCostRng.Cells(i)
  133.  
  134. profit = (boxEarnings - prodCost) / prodCost * 100
  135.  
  136. Debug.Print (nameRng.Cells(i) & " (" & genreRng.Cells(i) & ") - " & profit)
  137.  
  138.  
  139. If profit > maxProfit Then
  140. maxProfit = profit
  141. maxProfitIndex = i
  142. End If
  143. End If
  144. Next i
  145.  
  146. FindMovieProfitByGenre = nameRng(maxProfitIndex)
  147.  
  148.  
  149. End Function
  150.  
  151. ============================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement