Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.33 KB | None | 0 0
  1. Public coursename As String
  2. Public coursesemester As String
  3. Public iNameCount As Integer
  4. Public names As Variant
  5.  
  6.  
  7. Public Function get_names() As String() 'this function loops through the original data and provides a 2D array of the names of the course outcomes
  8. Sheets("RawData").Activate 'necessary
  9. ActiveCell.Offset(0, 1).Select
  10. Dim names(1 To 50, 0 To 10) As String
  11. 'Dim iNameCount As Integer
  12. iNameCount = 0
  13. i = 2 'initial point
  14. j = 2
  15. Do Until IsEmpty(Sheets("RawData").Cells(i, j)) 'looping through to get data
  16. Sheets("RawData").Cells(i, j).Select
  17. If IsEmpty(ActiveCell) Then
  18. MsgBox "Exiting Do"
  19. Exit Do
  20. Else
  21. title = Cells(i, j).Value 'just getting name again
  22. position1 = InStr(title, "(")
  23. position2 = InStr(title, ")")
  24. Length = position2 - position1 - 1
  25. test = Mid(title, position1 + 1, Length)
  26. iNameCount = iNameCount + 1 'counter for positions in array
  27. names(iNameCount, 0) = test 'this time we are going to store it in an array
  28. j = j + 3
  29. k = k + 1
  30. End If
  31. Loop
  32. For i = 1 To iNameCount 'this will be used later for the frequency calculation
  33. names(i, 1) = 0
  34. names(i, 2) = 0
  35. names(i, 3) = 0
  36. names(i, 4) = 0
  37. names(i, 5) = 0
  38. Next i
  39. get_names = names 'the way VBA returns the array
  40. End Function
  41.  
  42. Public Sub create_spreadsheet(name As String) 'nice little function to create the spreadsheets
  43. Dim WS As Worksheet
  44. Set WS = Sheets.Add
  45. WS.name = name
  46. Sheets(name).Cells(1, 1).Value = coursename
  47. Sheets(name).Cells(2, 1).Value = coursesemester
  48. Set WS = Nothing
  49. End Sub
  50.  
  51. Public Sub border(name As String, row As Integer, column As Integer, n As Integer) 'function to create a border around a entire frequency table
  52. here1 = Sheets(name).Cells(row, column).Address
  53. here2 = Sheets(name).Cells(row + n, column + iNameCount).Address
  54. Sheets(name).Activate
  55. Range(here1 & ":" & here2).Select
  56. Selection.borders(xlDiagonalDown).LineStyle = xlNone
  57. Selection.borders(xlDiagonalUp).LineStyle = xlNone
  58. With Selection.borders(xlEdgeLeft)
  59. .LineStyle = xlContinuous
  60. .ColorIndex = 0
  61. .TintAndShade = 0
  62. .Weight = xlThin
  63. End With
  64. With Selection.borders(xlEdgeTop)
  65. .LineStyle = xlContinuous
  66. .ColorIndex = 0
  67. .TintAndShade = 0
  68. .Weight = xlThin
  69. End With
  70. With Selection.borders(xlEdgeBottom)
  71. .LineStyle = xlContinuous
  72. .ColorIndex = 0
  73. .TintAndShade = 0
  74. .Weight = xlThin
  75. End With
  76. With Selection.borders(xlEdgeRight)
  77. .LineStyle = xlContinuous
  78. .ColorIndex = 0
  79. .TintAndShade = 0
  80. .Weight = xlThin
  81. End With
  82. With Selection.borders(xlInsideVertical)
  83. .LineStyle = xlContinuous
  84. .ColorIndex = 0
  85. .TintAndShade = 0
  86. .Weight = xlThin
  87. End With
  88. With Selection.borders(xlInsideHorizontal)
  89. .LineStyle = xlContinuous
  90. .ColorIndex = 0
  91. .TintAndShade = 0
  92. .Weight = xlThin
  93. End With
  94. End Sub
  95.  
  96. Public Sub response_key(name As String, row As Integer, column As Integer) 'this generates the response key
  97. Sheets(name).Activate
  98. Sheets(name).Cells(row, column).Value = "Response Key:"
  99. Sheets(name).Cells(row, column).Font.Bold = True
  100. Sheets(name).Cells(row + 1, column).Value = "1:Strongly Agree"
  101. Sheets(name).Cells(row + 2, column).Value = "2:Agree"
  102. Sheets(name).Cells(row + 3, column).Value = "3:Neither Agree Nor Disagree"
  103. Sheets(name).Cells(row + 4, column).Value = "4: Disagree"
  104. Sheets(name).Cells(row + 5, column).Value = "5:Strongly Disagree"
  105. here1 = Sheets(name).Cells(row, column).Address
  106. here2 = Sheets(name).Cells(row + 5, column + 3).Address
  107. Range(here1 & ":" & here2).Select
  108.  
  109. Selection.borders(xlDiagonalDown).LineStyle = xlNone
  110. Selection.borders(xlDiagonalUp).LineStyle = xlNone
  111. With Selection.borders(xlEdgeLeft)
  112. .LineStyle = xlContinuous
  113. .ColorIndex = 0
  114. .TintAndShade = 0
  115. .Weight = xlThick
  116. End With
  117. With Selection.borders(xlEdgeTop)
  118. .LineStyle = xlContinuous
  119. .ColorIndex = 0
  120. .TintAndShade = 0
  121. .Weight = xlThick
  122. End With
  123. With Selection.borders(xlEdgeBottom)
  124. .LineStyle = xlContinuous
  125. .ColorIndex = 0
  126. .TintAndShade = 0
  127. .Weight = xlThick
  128. End With
  129. With Selection.borders(xlEdgeRight)
  130. .LineStyle = xlContinuous
  131. .ColorIndex = 0
  132. .TintAndShade = 0
  133. .Weight = xlThick
  134. End With
  135. Selection.borders(xlInsideVertical).LineStyle = xlNone
  136. Selection.borders(xlInsideHorizontal).LineStyle = xlNone
  137.  
  138. End Sub
  139.  
  140. Private Sub thick_bottom_border(name As String, row As Integer, column As Integer)
  141. With Sheets(name).Cells(row, column).borders(xlEdgeBottom)
  142. .LineStyle = xlContinuous
  143. .ColorIndex = xlAutomatic
  144. .TintAndShade = 0
  145. .Weight = xlMedium
  146. End With
  147. With Sheets(name).Cells(row, column + 1).borders(xlEdgeBottom)
  148. .LineStyle = xlContinuous
  149. .ColorIndex = xlAutomatic
  150. .TintAndShade = 0
  151. .Weight = xlMedium
  152. End With
  153.  
  154. End Sub
  155.  
  156. Private Sub thin_bottom_border(name As String, row As Integer, column As Integer)
  157. With Sheets(name).Cells(row, column).borders(xlEdgeBottom)
  158. .LineStyle = xlContinuous
  159. .ColorIndex = xlAutomatic
  160. .TintAndShade = 0
  161. .Weight = xlThin
  162. End With
  163. With Sheets(name).Cells(row, column + 1).borders(xlEdgeBottom)
  164. .LineStyle = xlContinuous
  165. .ColorIndex = xlAutomatic
  166. .TintAndShade = 0
  167. .Weight = xlThin
  168. End With
  169.  
  170. End Sub
  171.  
  172.  
  173. Public Function Originalnames(name As Variant) As String
  174. 'MsgBox "inside of originalnames"
  175. Dim thenames(1 To 20) As String
  176. thenames(1) = "PO#1: This course provided students with: An ability to apply knowledge of mathematics, science, and engineering."
  177. thenames(2) = "PO#2: This course provided students with: An ability to design and conduct experiments, as well as analyze and interpret data."
  178. thenames(3) = "PO#3: This course provided students with: An ability to design a system, component, or process to meet desired needs."
  179. thenames(4) = "PO#4: This course provided students with: An ability to function on multi-disciplinary teams."
  180. thenames(5) = "PO#5: This course provided students with: An ability to identify, formulate, and solve engineering problems."
  181. thenames(6) = "PO#6: This course provided students with: An understanding of professional and ethical responsibility."
  182. thenames(7) = "PO#7: This course provided students with: An ability to communicate effectively."
  183. thenames(8) = "PO#7W: This course provided students with: An ability to communicate effectively through written reports."
  184. thenames(9) = "PO#8: This course provided students with: The broad education necessary to understand the impact of engineering solutions in a global and societal context."
  185. thenames(10) = "PO#9: This course provided students with: A recognition of the need for, and an ability to engage in life-long learning."
  186. thenames(11) = "PO#10: This course provided students with: A knowledge of contemporary engineering issues."
  187. thenames(12) = "PO#11: This course provided students with: An ability to use the techniques, skills, and modern engineering tools necessary for engineering practice."
  188. thenames(13) = "PO#12: This course provided students with: An ability to apply principles of engineering, basic science, and mathematics (including multivariate calculus and differential equations)to model, analyze, design, and realize physical systems, components or processes."
  189. thenames(14) = "PO#13: This course provided students with: An ability to work professionally in both thermal and mechanical systems areas."
  190. thenames(15) = "PO#13M: This course provided students with: An ability to work professionally in mechanical systems areas."
  191. thenames(16) = "PO#13T: This course provided students with: An ability to work professionally in thermal systems areas."
  192.  
  193. For i = 1 To 16
  194. position2 = InStr(thenames(i), ":")
  195. 'MsgBox position2
  196. Value = Mid(thenames(i), 1, position2 - 1)
  197. 'MsgBox Value
  198.  
  199. If Value = name Then
  200. 'MsgBox "Positive match Scotty!"
  201. Originalnames = thenames(i)
  202. End If
  203. Next i
  204.  
  205. End Function
  206.  
  207.  
  208. Public Sub Charts_Click() 'LOOK AT THIS LAST.
  209. 'this function just takes all the created charts and compiles them in one book.
  210. icounter = 0 'required to make the code only go two graphs across
  211. w = 3 'starting points, w,k
  212. k = 1
  213.  
  214. For i = 1 To iNameCount
  215. icounter = icounter + 1 'how many have we gone through
  216. Sheets(names(i, 0)).Activate 'necessary as we need to copy the chart
  217. ActiveSheet.ChartObjects("Chart 2").Activate 'activating the chart to copy it
  218. ActiveChart.ChartArea.Copy 'I wonder what that .Copy does
  219. Sheets("All_Charts").Select 'now we have the chart, moving to the right spreadsheet
  220. ActiveSheet.Cells(w, k).Select 'this represents the upper-left corner of the graph
  221. ActiveSheet.Paste 'pasting it in
  222. ActiveSheet.ChartObjects("Chart " & i).Activate 'the i is the chart number, linear as we paste them
  223. ActiveSheet.Shapes("Chart " & i).ScaleWidth 0.7625, msoFalse, msoScaleFromTopLeft 'scaling it down
  224. ActiveSheet.Shapes("Chart " & i).ScaleHeight 0.6840277778, msoFalse, msoScaleFromTopLeft 'scaling it down
  225.  
  226. If icounter < 2 Then 'if statement to make it put only two charts next to eachother
  227. k = k + 6 'essentially this happens once
  228. Else
  229. k = 1
  230. w = w + 12
  231. icounter = 0
  232. End If
  233. Next i
  234.  
  235. If counter = 0 Then
  236. w = w - 12 'fixes a problem with the position of the stuff below
  237. End If
  238.  
  239. For i = 1 To iNameCount
  240. Sheets("All_Charts").Cells(w + 12 + i, 1).Value = Originalnames(names(i, 0))
  241. Next i
  242. Call response_key("All_Charts", w + 13 + iNameCount, 1)
  243.  
  244. End Sub
  245.  
  246. Public Sub CommandButton1_Click()
  247. 'gets course name and semester for archiving purposes
  248. coursename = InputBox(Prompt:="What is the name of this course?", title:="ENTER COURSE NAME", Default:="ME 101")
  249. coursesemester = InputBox(Prompt:="What is the semester of this course?", title:="ENTER COURSE SEMESTER", Default:="Spring 2011")
  250. ' below converts text to numerical equivalents
  251. ActiveSheet.name = "RawData" 'Renames Data sheet so that we can reference it later.
  252. Cells.Replace What:="Strongly Agree", Replacement:="1", LookAt:=xlWhole, MatchCase:=False
  253. Cells.Replace What:="Agree", Replacement:="2", LookAt:=xlWhole, MatchCase:=False
  254. Cells.Replace What:="Neither Agree nor Disagree", Replacement:="3", LookAt:=xlWhole, MatchCase:=False
  255. Cells.Replace What:="Disagree", Replacement:="4", LookAt:=xlWhole, MatchCase:=False
  256. Cells.Replace What:="Strongly Disagree", Replacement:="5", LookAt:=xlWhole, MatchCase:=False
  257.  
  258. 'adds some work sheets we will need later for data storage
  259. Call create_spreadsheet("FormattedData")
  260. Call create_spreadsheet("Frequency")
  261. Call create_spreadsheet("All_Charts")
  262. names = get_names
  263. End Sub
  264.  
  265. Public Sub CommandButton2_Click() 'this routine extracts the rawdata into the formatted data spreadsheet
  266. 'immediately below is probably not necessary. But it activates the right sheet.
  267. Sheets("FormattedData").Activate
  268. ActiveCell.Offset(0, 1).Select
  269. Sheets("RawData").Activate
  270. ActiveCell.Offset(0, 1).Select
  271. Dim i As Integer
  272. Dim j As Integer
  273. Dim w As Integer
  274. Dim k As Integer
  275. Dim Fir As Integer
  276. Dim Fic As Integer
  277. Dim n As Integer
  278.  
  279. 'i,j are for the RawData sheet cells. w,k are for FormattedData Cells
  280. 'row,column
  281. i = 2
  282. j = 2
  283. w = 3
  284. k = 3
  285. Sheets("RawData").Cells(i, j).Select
  286. For Position = 1 To iNameCount
  287. 'Sheets("RawData").Activate
  288. Sheets("RawData").Cells(i, j).Select 'selecting the cell in the loop
  289. test = names(Position, 0)
  290. Sheets("FormattedData").Cells(w, k).Value = "Response to " & test 'again, just formatting stuff
  291. Sheets("FormattedData").Cells(w, k).Font.Bold = True
  292. 'Sheets("formattedData").Cells(w, k).Select
  293. 'Call border("FormattedData", w, k)
  294. 'The following is for the inner loop, that transfers the data between the two sheets
  295. Rir = i 'R = raw data, I = inner (as in loop), r = row, c = column
  296. Ric = j + 1
  297. Fir = w + 1 'F = Formatted data, I = inner (as in loop), r = row, c = column
  298. Fic = k
  299. n = 0 ' initializing counter to get average, number of entries
  300. flag = 0 'in case we have an <unanswered> occurance
  301. Total = 0 'initializing counter to get counter for average
  302. Do Until IsEmpty(Sheets("RawData").Cells(Rir, Ric)) 'Loop to transfer data
  303. n = n + 1 'Counter, for number of students
  304. If IsEmpty(ActiveCell) Then
  305. Exit Do
  306. Else
  307. If Sheets("RawData").Cells(Rir, Ric).Value <> "<Unanswered>" Then '<Unanswered> has no bearance on the results
  308. Select Case Sheets("RawData").Cells(Rir, Ric) 'counting the numbers.
  309. Case 1
  310. names(Position, 1) = names(Position, 1) + 1
  311. Case 2
  312. names(Position, 2) = names(Position, 2) + 1
  313. Case 3
  314. names(Position, 3) = names(Position, 3) + 1
  315. Case 4
  316. names(Position, 4) = names(Position, 4) + 1
  317. Case 5
  318. names(Position, 5) = names(Position, 5) + 1
  319. End Select
  320. Sheets("FormattedData").Cells(Fir, Fic).Value = Sheets("RawData").Cells(Rir, Ric).Value 'moving data
  321. 'Call border("FormattedData", Fir, Fic)
  322. Total = Total + Sheets("FormattedData").Cells(Fir, Fic).Value 'running total to calc average
  323. Else
  324. flag = flag + 1 'this is to fix for avg error in the event <Unanswered> was encountered
  325. End If
  326. Sheets("FormattedData").Cells(Fir, 2).Value = n 'formatting, counting students
  327. 'Call border("FormattedData", Fir, 2)
  328. Rir = Rir + 1
  329. Fir = Fir + 1
  330. End If
  331. Loop
  332. flag = n - flag 'corrects for an <unanswered> cell
  333. avg = Total / flag ' calcing average
  334. Sheets("FormattedData").Cells(n + 4, Fic).Value = avg 'Putting in average, plus 4 is to get below the bottom of data
  335. Sheets("FormattedData").Cells(n + 4, Fic).Font.Bold = True
  336. j = j + 3 'every significant column in RawData is 3 over
  337. k = k + 1 'moving down.
  338. Next Position
  339. Sheets("FormattedData").Cells(n + 4, 2).Value = "Average:" 'Makes it pretty. One might say formatted
  340. Sheets("FormattedData").Cells(n + 4, 2).Font.Bold = True
  341. Sheets("FormattedData").Cells(3, 2).Value = "Student #"
  342. Call border("FormattedData", 3, 2, n)
  343. Sheets("FormattedData").Cells(3, 2).Font.Bold = True
  344. For i = 1 To iNameCount
  345. Sheets("FormattedData").Cells(n + 6, 2).Value = Originalnames(names(i, 0))
  346. n = n + 1
  347. Next i
  348. Call response_key("FormattedData", n + 7, 2)
  349. End Sub
  350.  
  351. Public Sub CommandButton3_Click() ' this generates the frequency spreadsheet, as well as graphs associated with freq
  352. Sheets("RawData").Activate 'again, might not be necessary
  353. ActiveCell.Offset(0, 1).Select
  354. Dim i As Integer
  355. Dim j As Integer
  356. Dim title
  357. Dim MyColumn As String, Here As String
  358. Dim test As String
  359. Dim w As Integer, k As Integer
  360. 'initializing the start point for the data
  361. i = 2
  362. j = 2
  363. w = 3
  364. k = 1
  365. Count = 0
  366. Sheets("RawData").Cells(i, j).Select 'selecting the first cell to start the moving.
  367. For Position = 1 To iNameCount 'this will loop through our array of names to get the data
  368. Count = Count + 1
  369. Sheets("RawData").Activate
  370. Sheets("RawData").Cells(i, j).Select
  371. test = names(Position, 0)
  372. 'MsgBox test
  373. Call create_spreadsheet(test)
  374. Sheets("RawData").Activate 'this is required, else a error occurs.
  375. Sheets("Frequency").Cells(w, k).Value = coursename & " " & test
  376. Call thick_bottom_border("Frequency", w, k)
  377. Sheets("Frequency").Cells(w, k).Font.Bold = True
  378. Sheets("Frequency").Cells(w + 1, k).Value = "Response"
  379. Call thin_bottom_border("Frequency", w + 1, k)
  380. Sheets("Frequency").Cells(w + 1, k + 1).Value = "Frequency"
  381. Sheets("Frequency").Cells(w + 1, k).Font.Italic = True
  382. Sheets("Frequency").Cells(w + 1, k + 1).Font.Italic = True
  383. n = 1
  384. 'generating the numbers to make the 1 - 5 on the left for frequency bin
  385. For t = 2 To 6
  386. Sheets("Frequency").Cells(w + t, k).Value = n
  387. n = n + 1
  388. Next t
  389. Sheets("frequency").Cells(w + 7, k).Value = "More"
  390. Call thick_bottom_border("Frequency", w + 7, k)
  391. 'places values in the proper area
  392. Sheets("Frequency").Cells(w + 2, k + 1).Value = names(Position, 1)
  393. Here = Sheets("Frequency").Cells(w + 2, k + 1).Address
  394. Sheets("Frequency").Cells(w + 3, k + 1).Value = names(Position, 2)
  395. Sheets("Frequency").Cells(w + 4, k + 1).Value = names(Position, 3)
  396. Sheets("Frequency").Cells(w + 5, k + 1).Value = names(Position, 4)
  397. Sheets("Frequency").Cells(w + 6, k + 1).Value = names(Position, 5)
  398. loc1 = w + 2 'this is for the generation of graphs
  399. loc2 = w + 6
  400. 'j = j + 3
  401.  
  402. If Count <> 4 Then 'this just limits how far horizontally it goes in the frequency part.
  403. k = k + 3
  404. Else
  405. k = 1
  406. w = w + 10
  407. Count = 0
  408. End If
  409. ' Get the address of the active cell in the current selection
  410. 'Here = Sheets("Frequency").Cells(w + 6, k + 1).Address done above
  411.  
  412. ' Because .Address is $<columnletter>$<rownumber>, drop the first
  413. ' character and the characters after the column letter(s). WE NEED THIS TO GENERATE THE GRAPH
  414. MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here, "$") - 2)
  415.  
  416. 'The rest will create the histogram.
  417. 'the activates are NECESSARY because otherwise the chart-creation commands bark at you
  418. Sheets(test).Activate
  419. ActiveSheet.Shapes.AddChart.Select
  420. ActiveChart.ChartType = xlColumnClustered
  421. ActiveChart.SeriesCollection.NewSeries
  422. ActiveChart.SeriesCollection(1).name = "=""Frequency"""
  423. ActiveChart.SeriesCollection(1).Values = "=Frequency!$" + MyColumn + "$" + CStr(loc1) + ":$" + MyColumn + "$" + CStr(loc2) 'converts the frequency data to an excel-based location for the graph
  424. Sheets(test).Activate
  425. ActiveChart.HasTitle = True
  426. ActiveChart.ChartTitle.Select
  427. chartname = coursename & " " & test
  428. ActiveChart.ChartTitle.Text = chartname 'chart title: PO#1 etc
  429. ActiveChart.Location Where:=xlLocationAsObject, name:=test 'giving the chart a title
  430. ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis) 'adds a horizontal axis
  431. Selection.Format.TextFrame2.TextRange.Characters.Text = "Response" 'name of axis
  432. ActiveChart.SetElement (msoElementPrimaryValueAxisTitleRotated) 'adds a vertical axis
  433. ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Frequency" 'name of axis
  434. ActiveChart.SeriesCollection(2).Delete 'Slight data error in collecting numbers
  435. ActiveChart.Parent.Cut
  436. Range("A1").Select
  437. ActiveSheet.Paste
  438. Sheets(test).Cells(16, 1).Value = Originalnames(test)
  439. Call response_key(test, 18, 1)
  440. Next Position
  441. End Sub
  442.  
  443. Private Sub CommandButton4_Click() 'this is the easy button, runs all the buttons above for ease of use
  444. now1 = Timer
  445. CommandButton1_Click
  446. CommandButton2_Click
  447. CommandButton3_Click
  448. Charts_Click
  449. now2 = Timer
  450. timed = now2 - now1
  451. MsgBox "That was easy. It took " & timed & " seconds to execute"
  452.  
  453. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement