Hello everyone,
My problem is fairly simple. I have a table I am working with which divides students into subjects Art or Math. For example,
Student|Subj. | T | | M
Kayline | Arts | 1 | 3 | 4
Loloita | Arts | 0 | 2 | 1
Gerard | Arts| 4 | 4 | 2
Jocelyn | Math| 2 | 2 | 3
.
.
.
I now create 2 new tables which calculate the mode of values ranging from 0-4 for Arts students and Math Students. I then create 2 new tables which calculate the percentage of these modes relative to all values. For example, 20% of the answers for Question "T" are 1 for Arts students. I then create a table to show all this.
I have managed to do this with Record Macro. However my main problem is, is there a way I can make the macro itself stop counting at the last student who takes Art instead of manually having to add the cell number. And the same goes for Math table. Is there a way I can get the macro to start counting from the first Math student until the last without having to manually plug in cell numbers?
Current Code:
Sub Test2()
'
' Test2 Macro
'
'
Sheets.Add After:=ActiveSheet
Range("B1").Select
ActiveCell.FormulaR1C1 = "t"
Range("C1").Select
ActiveCell.FormulaR1C1 = "c"
Range("D1").Select
ActiveCell.FormulaR1C1 = "m"
Range("A2").Select
ActiveCell.FormulaR1C1 = "0"
Range("A3").Select
ActiveCell.FormulaR1C1 = "1"
Range("A4").Select
ActiveCell.FormulaR1C1 = "2"
Range("A5").Select
ActiveCell.FormulaR1C1 = "3"
Range("A6").Select
ActiveCell.FormulaR1C1 = "4"
Range("B2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!R3C5:R34C5,RC[-1])"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B6"), Type:=xlFillDefault
Range("B2:B6").Select
Range("C2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!R3C6:R34C6,RC[-2])"
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C6"), Type:=xlFillDefault
Range("C2:C6").Select
Range("D2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!R3C7:R34C7,RC[-3])"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D6"), Type:=xlFillDefault
Range("D2:D6").Select
Range("B8").Select
ActiveCell.FormulaR1C1 = "t"
Range("C8").Select
ActiveCell.FormulaR1C1 = "c"
Range("D8").Select
ActiveCell.FormulaR1C1 = "m"
Range("A9").Select
ActiveCell.FormulaR1C1 = "0"
Range("A10").Select
ActiveCell.FormulaR1C1 = "1"
Range("A11").Select
ActiveCell.FormulaR1C1 = "2"
Range("A12").Select
ActiveCell.FormulaR1C1 = "3"
Range("A13").Select
ActiveCell.FormulaR1C1 = "4"
Range("A14").Select
ActiveCell.FormulaR1C1 = "5"
Range("A14").Select
ActiveCell.FormulaR1C1 = ""
Range("B9").Select
ActiveCell.FormulaR1C1 = "=(R[-7]C/(COUNT(Sheet1!R3C5:R34C5)))*100"
Range("B9").Select
Selection.AutoFill Destination:=Range("B9:B13"), Type:=xlFillDefault
Range("B9:B13").Select
Range("C9").Select
ActiveCell.FormulaR1C1 = "=(R[-7]C/(COUNT(Sheet1!R3C6:R34C6)))*100"
Range("C9").Select
Selection.AutoFill Destination:=Range("C9:C13"), Type:=xlFillDefault
Range("C9:C13").Select
Range("D9").Select
ActiveCell.FormulaR1C1 = "=(R[-7]C/(COUNT(Sheet1!R3C7:R34C7)))*100"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D13"), Type:=xlFillDefault
Range("D9:D13").Select
Range("A8:D13").Select
ActiveSheet.Shapes.AddChart2(297, xlColumnStacked100).Select
ActiveChart.SetSourceData Source:=Range("Sheet3!$A$8:$D$13")
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.FullSeriesCollection(1).ApplyDataLabels
ActiveChart.FullSeriesCollection(2).Select
ActiveChart.FullSeriesCollection(2).ApplyDataLabels
ActiveChart.FullSeriesCollection(3).Select
ActiveChart.FullSeriesCollection(3).ApplyDataLabels
Range("T21").Select
Sheets("Sheet1").Select
End Sub
My problem is fairly simple. I have a table I am working with which divides students into subjects Art or Math. For example,
Student|Subj. | T | | M
Kayline | Arts | 1 | 3 | 4
Loloita | Arts | 0 | 2 | 1
Gerard | Arts| 4 | 4 | 2
Jocelyn | Math| 2 | 2 | 3
.
.
.
I now create 2 new tables which calculate the mode of values ranging from 0-4 for Arts students and Math Students. I then create 2 new tables which calculate the percentage of these modes relative to all values. For example, 20% of the answers for Question "T" are 1 for Arts students. I then create a table to show all this.
I have managed to do this with Record Macro. However my main problem is, is there a way I can make the macro itself stop counting at the last student who takes Art instead of manually having to add the cell number. And the same goes for Math table. Is there a way I can get the macro to start counting from the first Math student until the last without having to manually plug in cell numbers?
Current Code:
Sub Test2()
'
' Test2 Macro
'
'
Sheets.Add After:=ActiveSheet
Range("B1").Select
ActiveCell.FormulaR1C1 = "t"
Range("C1").Select
ActiveCell.FormulaR1C1 = "c"
Range("D1").Select
ActiveCell.FormulaR1C1 = "m"
Range("A2").Select
ActiveCell.FormulaR1C1 = "0"
Range("A3").Select
ActiveCell.FormulaR1C1 = "1"
Range("A4").Select
ActiveCell.FormulaR1C1 = "2"
Range("A5").Select
ActiveCell.FormulaR1C1 = "3"
Range("A6").Select
ActiveCell.FormulaR1C1 = "4"
Range("B2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!R3C5:R34C5,RC[-1])"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B6"), Type:=xlFillDefault
Range("B2:B6").Select
Range("C2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!R3C6:R34C6,RC[-2])"
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C6"), Type:=xlFillDefault
Range("C2:C6").Select
Range("D2").Select
ActiveCell.FormulaR1C1 = "=COUNTIF(Sheet1!R3C7:R34C7,RC[-3])"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D6"), Type:=xlFillDefault
Range("D2:D6").Select
Range("B8").Select
ActiveCell.FormulaR1C1 = "t"
Range("C8").Select
ActiveCell.FormulaR1C1 = "c"
Range("D8").Select
ActiveCell.FormulaR1C1 = "m"
Range("A9").Select
ActiveCell.FormulaR1C1 = "0"
Range("A10").Select
ActiveCell.FormulaR1C1 = "1"
Range("A11").Select
ActiveCell.FormulaR1C1 = "2"
Range("A12").Select
ActiveCell.FormulaR1C1 = "3"
Range("A13").Select
ActiveCell.FormulaR1C1 = "4"
Range("A14").Select
ActiveCell.FormulaR1C1 = "5"
Range("A14").Select
ActiveCell.FormulaR1C1 = ""
Range("B9").Select
ActiveCell.FormulaR1C1 = "=(R[-7]C/(COUNT(Sheet1!R3C5:R34C5)))*100"
Range("B9").Select
Selection.AutoFill Destination:=Range("B9:B13"), Type:=xlFillDefault
Range("B9:B13").Select
Range("C9").Select
ActiveCell.FormulaR1C1 = "=(R[-7]C/(COUNT(Sheet1!R3C6:R34C6)))*100"
Range("C9").Select
Selection.AutoFill Destination:=Range("C9:C13"), Type:=xlFillDefault
Range("C9:C13").Select
Range("D9").Select
ActiveCell.FormulaR1C1 = "=(R[-7]C/(COUNT(Sheet1!R3C7:R34C7)))*100"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D13"), Type:=xlFillDefault
Range("D9:D13").Select
Range("A8:D13").Select
ActiveSheet.Shapes.AddChart2(297, xlColumnStacked100).Select
ActiveChart.SetSourceData Source:=Range("Sheet3!$A$8:$D$13")
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.FullSeriesCollection(1).ApplyDataLabels
ActiveChart.FullSeriesCollection(2).Select
ActiveChart.FullSeriesCollection(2).ApplyDataLabels
ActiveChart.FullSeriesCollection(3).Select
ActiveChart.FullSeriesCollection(3).ApplyDataLabels
Range("T21").Select
Sheets("Sheet1").Select
End Sub