veronikaaa86

Exam Prep - final

Jan 20th, 2022 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.76 KB | None | 0 0
  1. Sub Main()
  2. Dim lastRow As Integer
  3. lastRow = Cells(Rows.Count, 1).End(xlUp).Row '99
  4.  
  5. InsertColumn
  6. SetExpenses (lastRow) '99
  7. SetProfit (lastRow) '99
  8. SetFullName (lastRow) '99
  9. SetDeliveryDate (lastRow) '99
  10.  
  11. Range("G" & lastRow + 1) = "=SUM(G2:G" & lastRow & ")" '99
  12. Range("H" & lastRow + 1) = "=SUM(H2:H" & lastRow & ")" '99
  13. Range("I" & lastRow + 1) = "=SUM(I2:I" & lastRow & ")" '99
  14.  
  15. DeleteColumn '99
  16.  
  17. 'lastRow = Cells(Rows.Count, 1).End(xlUp).Row
  18.  
  19. Formatting (lastRow)
  20. End Sub
  21.  
  22. Sub SetDeliveryDate(lastRow As Integer)
  23. For i = 2 To lastRow
  24. Range("F" & i) = "=E" & i & "+7"
  25. Next
  26. End Sub
  27.  
  28. Sub SetFullName(lastRow As Integer)
  29.  
  30. For i = 2 To lastRow
  31. Dim fullName, firstName, lastName As String
  32. firstName = Range("A" & i)
  33. lastName = Range("B" & i)
  34.  
  35. fullName = firstName & " " & lastName
  36.  
  37. Range("C" & i) = fullName
  38. Next
  39. End Sub
  40.  
  41. Sub SetExpenses(lastRow As Integer)
  42. For i = 2 To lastRow
  43. Dim contractPrice, expense As Variant
  44. contractPrice = Range("G" & i)
  45.  
  46. If contractPrice < 10000 Then
  47. expense = contractPrice * 0.03
  48. ElseIf contractPrice <= 30000 Then
  49. expense = contractPrice * 0.028
  50. ElseIf contractPrice <= 100000 Then
  51. expense = contractPrice * 0.025
  52. Else
  53. expense = contractPrice * 0.02
  54. End If
  55.  
  56.  
  57. Range("H" & i) = expense
  58. Next
  59. End Sub
  60.  
  61. Sub SetProfit(lastRow As Integer)
  62. For i = 2 To lastRow
  63. Dim profit, contractPrice, expense As Variant
  64. contractPrice = Range("G" & i)
  65. expense = Range("H" & i)
  66.  
  67. 'profit = contractPrice - expense
  68.  
  69. 'Range("I" & i) = profit
  70.  
  71. Range("I" & i) = "=G" & i & "-H" & i
  72. Next
  73. End Sub
  74.  
  75. Sub InsertColumn()
  76. Columns("E:E").Select
  77. Selection.Insert Shift:=xlToRight
  78. Range("E1").Select
  79. ActiveCell.FormulaR1C1 = "Expected Delivery Date"
  80. Range("E2").Select
  81.  
  82. Columns("C:C").Select
  83. Selection.Insert Shift:=xlToRight
  84. Range("C1").Select
  85. ActiveCell.FormulaR1C1 = "Full Name"
  86. Range("C2").Select
  87. End Sub
  88.  
  89. Sub DeleteColumn()
  90. Columns("A:B").Select
  91. Selection.Delete Shift:=xlToLeft
  92. Range("A1").Select
  93. End Sub
  94.  
  95. Sub Formatting(lastRow As Integer)
  96. Rows("1:1").Select
  97. Selection.Insert Shift:=xlDown
  98. Range("A1:G1").Select
  99. With Selection
  100. .HorizontalAlignment = xlCenter
  101. .VerticalAlignment = xlBottom
  102. .AddIndent = False
  103. .IndentLevel = 0
  104. .ReadingOrder = xlContext
  105. .MergeCells = False
  106. End With
  107. Selection.Merge
  108. ActiveCell.FormulaR1C1 = "Clients And Contracts"
  109. Range("A1:G1").Select
  110. With Selection.Interior
  111. .Pattern = xlSolid
  112. .PatternColorIndex = xlAutomatic
  113. .ThemeColor = xlThemeColorAccent1
  114. .TintAndShade = -0.499984740745262
  115. .PatternTintAndShade = 0
  116. End With
  117. With Selection.Font
  118. .ThemeColor = xlThemeColorDark1
  119. End With
  120. Selection.Font.Bold = True
  121. With Selection.Font
  122. .Name = "Calibri"
  123. .Size = 16
  124. .ThemeColor = xlThemeColorDark1
  125. .ThemeFont = xlThemeFontMinor
  126. End With
  127.  
  128. Range("A2:G2").Select
  129. With Selection.Interior
  130. .Pattern = xlSolid
  131. .PatternColorIndex = xlAutomatic
  132. .ThemeColor = xlThemeColorAccent1
  133. .TintAndShade = 0.399975585192419
  134. End With
  135. Selection.Font.Bold = True
  136. With Selection
  137. .HorizontalAlignment = xlCenter
  138. .VerticalAlignment = xlBottom
  139. .ReadingOrder = xlContext
  140. End With
  141. With Selection
  142. .HorizontalAlignment = xlCenter
  143. .VerticalAlignment = xlCenter
  144. .Orientation = 0
  145. .AddIndent = False
  146. .IndentLevel = 0
  147. .ShrinkToFit = False
  148. .ReadingOrder = xlContext
  149. .MergeCells = False
  150. End With
  151. With Selection
  152. .HorizontalAlignment = xlCenter
  153. .VerticalAlignment = xlCenter
  154. .WrapText = True
  155. .ReadingOrder = xlContext
  156. End With
  157.  
  158.  
  159.  
  160. ActiveWindow.SmallScroll Down:=96
  161. Range("A1:G" & lastRow).Select
  162. ActiveWindow.SmallScroll Down:=-126
  163. Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  164. Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  165. With Selection.Borders(xlEdgeLeft)
  166. .LineStyle = xlContinuous
  167. .ColorIndex = 0
  168. .TintAndShade = 0
  169. .Weight = xlThin
  170. End With
  171. With Selection.Borders(xlEdgeTop)
  172. .LineStyle = xlContinuous
  173. .ColorIndex = 0
  174. .TintAndShade = 0
  175. .Weight = xlThin
  176. End With
  177. With Selection.Borders(xlEdgeBottom)
  178. .LineStyle = xlContinuous
  179. .ColorIndex = 0
  180. .TintAndShade = 0
  181. .Weight = xlThin
  182. End With
  183. With Selection.Borders(xlEdgeRight)
  184. .LineStyle = xlContinuous
  185. .ColorIndex = 0
  186. .TintAndShade = 0
  187. .Weight = xlThin
  188. End With
  189. With Selection.Borders(xlInsideVertical)
  190. .LineStyle = xlContinuous
  191. .ColorIndex = 0
  192. .TintAndShade = 0
  193. .Weight = xlThin
  194. End With
  195. With Selection.Borders(xlInsideHorizontal)
  196. .LineStyle = xlContinuous
  197. .ColorIndex = 0
  198. .TintAndShade = 0
  199. .Weight = xlThin
  200. End With
  201. 'ActiveWindow.SmallScroll Down:=298
  202.  
  203.  
  204. Range("A" & lastRow + 2 & ":D" & lastRow + 2).Select
  205. With Selection
  206. .HorizontalAlignment = xlCenter
  207. .VerticalAlignment = xlBottom
  208. .ReadingOrder = xlContext
  209. End With
  210. Selection.Merge
  211. ActiveCell.FormulaR1C1 = "TOTAL"
  212. Range("A" & lastRow + 2 & ":D" & lastRow + 2).Select
  213. With Selection
  214. .HorizontalAlignment = xlRight
  215. .VerticalAlignment = xlBottom
  216. .ReadingOrder = xlContext
  217. .MergeCells = True
  218. End With
  219. Range("E" & lastRow + 2 & ":G" & lastRow + 2).Select
  220. With Selection.Font
  221. .Name = "Calibri"
  222. .Size = 14
  223. .Underline = xlUnderlineStyleNone
  224. .ThemeColor = xlThemeColorLight1
  225. .TintAndShade = 0
  226. .ThemeFont = xlThemeFontMinor
  227. End With
  228. With Selection.Font
  229. .Name = "Calibri"
  230. .Size = 12
  231. .Underline = xlUnderlineStyleNone
  232. .ThemeColor = xlThemeColorLight1
  233. .TintAndShade = 0
  234. .ThemeFont = xlThemeFontMinor
  235. End With
  236. Selection.Font.Bold = True
  237. Range("A" & lastRow + 2 & ":D" & lastRow + 2).Select
  238. Selection.Font.Bold = True
  239. Range("A" & lastRow + 2 & ":G" & lastRow + 2).Select
  240. Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  241. Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  242. With Selection.Borders(xlEdgeLeft)
  243. .LineStyle = xlContinuous
  244. .ColorIndex = 0
  245. .TintAndShade = 0
  246. .Weight = xlThin
  247. End With
  248. With Selection.Borders(xlEdgeTop)
  249. .LineStyle = xlContinuous
  250. .ColorIndex = 0
  251. .TintAndShade = 0
  252. .Weight = xlThin
  253. End With
  254. With Selection.Borders(xlEdgeBottom)
  255. .LineStyle = xlContinuous
  256. .ColorIndex = 0
  257. .TintAndShade = 0
  258. .Weight = xlThin
  259. End With
  260. With Selection.Borders(xlEdgeRight)
  261. .LineStyle = xlContinuous
  262. .ColorIndex = 0
  263. .TintAndShade = 0
  264. .Weight = xlThin
  265. End With
  266. With Selection.Borders(xlInsideVertical)
  267. .LineStyle = xlContinuous
  268. .ColorIndex = 0
  269. .TintAndShade = 0
  270. .Weight = xlThin
  271. End With
  272. With Selection.Borders(xlInsideHorizontal)
  273. .LineStyle = xlContinuous
  274. .ColorIndex = 0
  275. .TintAndShade = 0
  276. .Weight = xlThin
  277. End With
  278. End Sub
  279.  
Add Comment
Please, Sign In to add comment