Advertisement
Guest User

vba

a guest
Feb 7th, 2017
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Function B15(bilkategori As String) As Long
  2. For i = 5 To 7
  3.     If Cells(i, 4).Value = bilkategori Then
  4.         Range("B15").Value = Cells(i, 5).Value 'når den finner bilkategori legger den tilsvarende døgnpris i B15
  5.    End If
  6. Next i
  7. End Function
  8.  
  9. Private Function B16(kmUt As Long, kmInn As Long)
  10. Range("B16").Value = kmInn - kmUt
  11. End Function
  12.  
  13. Private Function B17()
  14. Dim antDager As Double
  15. antDager = Range("B10").Value - Range("B9").Value
  16. Range("B17").Value = Excel.WorksheetFunction.RoundUp(antDager, 0)
  17. End Function
  18.  
  19. Private Function B18(bilkategori As String)
  20. Dim sum As Long
  21. For i = 5 To 7
  22.     If Cells(i, 4).Value = bilkategori Then
  23.         sum = Cells(i, 6).Value * Range("B17").Value
  24.         sum = Range("B16").Value - sum
  25.        
  26.         If sum > 0 Then
  27.             Range("B18").Value = sum
  28.         Else
  29.             Range("B18").Value = 0
  30.         End If
  31.        
  32.         Exit For
  33.     End If
  34. Next i
  35.  
  36. End Function
  37.  
  38. Private Function B19()
  39. Dim alder As Long
  40. alder = DateDiff("d", Range("b8").Value, Now)
  41. Range("B19").Value = alder / 365.25
  42. End Function
  43.  
  44. Private Function B20()
  45.     If Range("B7").Value = "Kvinne" Then
  46.         Range("B20").Value = 1 - Range("E17").Value
  47.     Else
  48.         Range("B20").Value = 1
  49.     End If
  50. End Function
  51.  
  52. Private Function B21()
  53.     If Range("B19").Value > Range("E16").Value Then
  54.         Range("B21").Value = 1 - Range("E18").Value
  55.     Else
  56.         Range("B21").Value = 1
  57.     End If
  58. End Function
  59.  
  60. Private Function B24(bilkategori As String)
  61. For i = 5 To 7
  62.     If Cells(i, 4).Value = bilkategori Then
  63.         Range("B24").Value = Cells(i, 5).Value * Range("B17").Value
  64.     End If
  65. Next i
  66.  
  67. End Function
  68.  
  69. Private Function B25(bilkategori As String)
  70. If Range("B18").Value > 0 Then
  71.     For i = 5 To 7
  72.         If Cells(i, 4).Value = bilkategori Then
  73.             Range("B25").Value = Cells(i, 7).Value * Range("B18").Value
  74.         End If
  75.     Next i
  76. End If
  77.    
  78. End Function
  79.  
  80. Private Function B26()
  81. For i = 11 To 13
  82.     If Cells(i, 4).Value = Range("B5").Value Then
  83.         Exit For
  84.     End If
  85. Next i
  86.  
  87. For j = 5 To 7
  88.     If Cells(10, j).Value = Range("B6").Value Then
  89.         Exit For
  90.     End If
  91. Next j
  92.  
  93. Range("B26").Value = Cells(i, j).Value
  94.  
  95.  
  96.  
  97. End Function
  98.  
  99. Private Function B27()
  100. Range("B27").Value = Range("B20").Value * Range("B21").Value
  101. End Function
  102.  
  103. Private Function B28()
  104. Range("B28").Value = (Range("B24").Value + Range("B25").Value + Range("B26").Value) * Range("B27").Value
  105. End Function
  106.  
  107. Private Function B29()
  108. If Range("B28").Value > Range("E19").Value Then
  109.     Range("B29").Value = -1 * ((Range("B28").Value - Range("E19").Value) * Range("E20").Value + Range("E19").Value * Range("E21").Value)
  110. Else
  111.     Range("B29").Value = -1 * (Range("B28").Value * Range("B21").Value)
  112. End If
  113. End Function
  114.  
  115. Private Function B30()
  116. Range("B30").Value = Range("B28").Value + Range("B29").Value
  117. End Function
  118.  
  119. Private Sub btnCalculate_Click()
  120. Call B15(Cells(4, 2).Value) 'henter info fra B4
  121. Call B16(Range("B11").Value, Range("B12").Value) 'henter verdiene fra B11 og B12
  122. Call B17
  123. Call B18(Range("B4").Value)
  124. Call B19
  125. Call B20
  126. Call B21
  127. Call B24(Range("B4").Value)
  128. Call B25(Range("B4").Value)
  129. Call B26
  130. Call B27
  131. Call B28
  132. Call B29
  133. Call B30
  134. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement