ExcelPupper
Board Regular
- Joined
- Mar 2, 2020
- Messages
- 112
- Office Version
- 2019
- Platform
- Windows
I have here a set of data wherein I need to make separate sheets for each class and add sum function on the row after the last data.
My problem is how to insert sum function for each sheets. Is it possible to use For Each Next Loop here?
Kindly check my data below:
My problem is how to insert sum function for each sheets. Is it possible to use For Each Next Loop here?
Kindly check my data below:
VBA Code:
Sub SumClass()
'
'
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
ActiveSheet.Range("$A$1:$C$6").AutoFilter Field:=1, Criteria1:="=AB", _
Operator:=xlOr, Criteria2:="=AC"
Range("A1:C6").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "A Class"
Range("C4").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("C5").Select
ActiveSheet.Previous.Select
Selection.End(xlUp).Select
ActiveSheet.Range("$A$1:$C$6").AutoFilter Field:=1, Criteria1:="=b*", _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$C$6").AutoFilter Field:=2, Criteria1:="=1*", _
Operator:=xlAnd
Range("A1:C6").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "B Class"
ActiveSheet.Paste
Range("C4").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("C5").Select
End Sub