Advertisement
veronikaaa86

Protocol Macro - final

Jan 13th, 2022 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. Sub Main()
  2.  
  3. End Sub
  4.  
  5. Sub CopyData()
  6. Dim col As Variant
  7. col = GetColAddress("Sheet0", "Username")
  8.  
  9. If col = False Then
  10. MsgBox "Username not found"
  11. Else
  12. Sheets("Sheet0").Select
  13. Columns(col).Select
  14. Selection.Copy
  15. Sheets("Protocol").Select
  16. Columns(1).Select
  17. ActiveSheet.Paste
  18. End If
  19.  
  20. End Sub
  21.  
  22. Function GetColAddress(sheetName, target As String)
  23. Dim col As Range
  24.  
  25. Set col = Sheets(sheetName).Rows(1).Find(What:=target)
  26.  
  27. If col Is Nothing Then
  28. GetColAddress = False
  29. Else
  30. GetColAddress = col.Column
  31. End If
  32. End Function
  33.  
  34. Sub InsertColumns()
  35. Sheets("Protocol").Select
  36. Range("B1").Select
  37. ActiveCell = "Course Points"
  38. Range("C1").Select
  39. ActiveCell = "Grade"
  40. Range("D1").Select
  41. ActiveCell = "Practical Points"
  42. Range("E1").Select
  43. ActiveCell = "Theoretical Points"
  44.  
  45. End Sub
  46.  
  47. Sub FormatHeader(lastRow As Integer)
  48. Range("A1:E" & lastRow).Select
  49. Selection.ColumnWidth = 30
  50. Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  51. Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  52. With Selection.Borders(xlEdgeLeft)
  53. .LineStyle = xlContinuous
  54. .ColorIndex = 0
  55. .TintAndShade = 0
  56. .Weight = xlThin
  57. End With
  58. With Selection.Borders(xlEdgeTop)
  59. .LineStyle = xlContinuous
  60. .ColorIndex = 0
  61. .TintAndShade = 0
  62. .Weight = xlThin
  63. End With
  64. With Selection.Borders(xlEdgeBottom)
  65. .LineStyle = xlContinuous
  66. .ColorIndex = 0
  67. .TintAndShade = 0
  68. .Weight = xlThin
  69. End With
  70. With Selection.Borders(xlEdgeRight)
  71. .LineStyle = xlContinuous
  72. .ColorIndex = 0
  73. .TintAndShade = 0
  74. .Weight = xlThin
  75. End With
  76. With Selection.Borders(xlInsideVertical)
  77. .LineStyle = xlContinuous
  78. .ColorIndex = 0
  79. .TintAndShade = 0
  80. .Weight = xlThin
  81. End With
  82. With Selection.Borders(xlInsideHorizontal)
  83. .LineStyle = xlContinuous
  84. .ColorIndex = 0
  85. .TintAndShade = 0
  86. .Weight = xlThin
  87. End With
  88. With Selection
  89. .HorizontalAlignment = xlGeneral
  90. .VerticalAlignment = xlBottom
  91. .WrapText = True
  92. .Orientation = 0
  93. .AddIndent = False
  94. .IndentLevel = 0
  95. .ShrinkToFit = False
  96. .ReadingOrder = xlContext
  97. .MergeCells = False
  98. End With
  99. Range("A1:E1").Select
  100. With Selection.Font
  101. .Name = "Calibri"
  102. .Size = 15
  103. .Underline = xlUnderlineStyleNone
  104. .ThemeColor = xlThemeColorLight1
  105. .TintAndShade = 0
  106. .ThemeFont = xlThemeFontMinor
  107. End With
  108. With Selection
  109. .HorizontalAlignment = xlGeneral
  110. .VerticalAlignment = xlCenter
  111. .WrapText = True
  112. .Orientation = 0
  113. .AddIndent = False
  114. .IndentLevel = 0
  115. .ShrinkToFit = False
  116. .ReadingOrder = xlContext
  117. .MergeCells = False
  118. End With
  119. With Selection
  120. .HorizontalAlignment = xlCenter
  121. .VerticalAlignment = xlCenter
  122. .WrapText = True
  123. .Orientation = 0
  124. .AddIndent = False
  125. .IndentLevel = 0
  126. .ShrinkToFit = False
  127. .ReadingOrder = xlContext
  128. .MergeCells = False
  129. End With
  130. With Selection.Interior
  131. .Pattern = xlSolid
  132. .PatternColorIndex = xlAutomatic
  133. .ThemeColor = xlThemeColorDark2
  134. .TintAndShade = 0
  135. .PatternTintAndShade = 0
  136. End With
  137. With ActiveWindow
  138. .SplitColumn = 0
  139. .SplitRow = 1
  140. End With
  141. ActiveWindow.FreezePanes = True
  142. End Sub
  143.  
  144. Sub CoursePoints(lastRow, percentPractical, percentTheoretical As Integer)
  145. '=D2*80/100 + E2*20/100
  146. Dim isNotParticipate As Boolean
  147.  
  148. For r = 2 To lastRow
  149. isNotParticipate = Range("D" & r) = "NO" And Range("E" & r) = "NO"
  150. If isNotParticipate Then
  151. Range("B" & r) = "Did not appear for the exam!"
  152. Else
  153. Range("B" & r) = _
  154. "=D" & r & "*" & percentPractical & "/100 + E" & r & "*" & percentTheoretical & "/100"
  155. End If
  156. Next
  157. End Sub
  158.  
  159. Sub PracticalAndTheoreticalPoints(lastRow As Integer)
  160. '=VLOOKUP(A2,'Practical Points'!A:B,2,FALSE)
  161. For r = 2 To lastRow
  162. Range("D" & r) = _
  163. "=VLOOKUP(A" & r & ",'Practical Points'!A:B,2,FALSE)"
  164. Range("E" & r) = _
  165. "=VLOOKUP(A" & r & ",'Theoretical Points'!A:B,2,FALSE)"
  166.  
  167. If Range("D" & r) = 0 And Range("E" & r) = 0 Then
  168. Range("D" & r) = "NO"
  169. Range("E" & r) = "NO"
  170. End If
  171. Next
  172.  
  173. End Sub
  174.  
  175. Sub Grade(lastRow, pointsFor5, pointsFor3 As Integer)
  176. '=IF(B2=100,6,IF(B2 <=70,3+2*(B2 -30)/(70-30),5+(B2 -70)/(95-70)))
  177.  
  178. For r = 2 To lastRow
  179. If Range("B" & r) = "Did not appear for the exam!" Then
  180. Range("C" & r) = ""
  181. ElseIf Range("B" & r) = 100 Then
  182. Range("C" & r) = 6
  183. ElseIf Range("B" & r) <= pointsFor5 Then
  184. Range("C" & r) = "=3+2*(B" & r & " -" & pointsFor3 & ")/(" & pointsFor5 & "-" & pointsFor3 & ")"
  185. If Range("C" & r) < 2 Then
  186. Range("C" & r) = 2
  187. ElseIf Range("C" & r) > 6 Then
  188. Range("C" & r) = 6
  189. End If
  190. Else
  191. Range("C" & r) = "=5+(B" & r & "-" & pointsFor5 & ")/(95-" & pointsFor5 & ")"
  192. If Range("C" & r) > 6 Then
  193. Range("C" & r) = 6
  194. End If
  195. End If
  196. Next
  197. End Sub
  198.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement