Hi,
I'm currently new in recording basic macro. Can someone help me get the unique values for in the account column and create each account a separate worksheet?
What I currently have is just for 3 items to filter the account columns for each items, copy the contents, create worksheet for each item and paste the contents on the worksheets but I may encounter other accounts than what I currently recorded.
Sorry for a messy code I am just a beginner with no training/basic knowledge or whatsoever.
Thank you very much!
I'm currently new in recording basic macro. Can someone help me get the unique values for in the account column and create each account a separate worksheet?
What I currently have is just for 3 items to filter the account columns for each items, copy the contents, create worksheet for each item and paste the contents on the worksheets but I may encounter other accounts than what I currently recorded.
Code:
Sub Collapse()
'
' Collapse Macro
'
'
ActiveSheet.ListObjects("Account").Range.AutoFilter Field:=3, Criteria1:= _
"Account1"
Range("Account[#All]").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
ActiveSheet.ListObjects.Add(xlSrcRange, , xlYes).Name = _
"Account1"
Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Formula = "=SUBTOTAL(109,_Account1[Amount])"
Cells(Rows.Count, "A").End(xlUp).Value = "Total"
ActiveSheet.Name = "Account1"
Sheets("GL Transaction").Select
ActiveSheet.ListObjects("Account").Range.AutoFilter Field:=3, Criteria1:= _
"Account2"
Range("Account[#All]").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
ActiveSheet.ListObjects.Add(xlSrcRange, , xlYes).Name = _
"Account2"
Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Formula = "=SUBTOTAL(109,_Account2[Amount])"
Cells(Rows.Count, "A").End(xlUp).Value = "Total"
ActiveSheet.Name = "Account2"
Sheets("GL Transaction").Select
ActiveSheet.ListObjects("Account").Range.AutoFilter Field:=3, Criteria1:= _
"Account3"
Range("Account[#All]").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
ActiveSheet.ListObjects.Add(xlSrcRange, , xlYes).Name = _
"Account3"
Cells(Rows.Count, "F").End(xlUp).Offset(1, 0).Formula = "=SUBTOTAL(109,_Account13[Amount])"
Cells(Rows.Count, "A").End(xlUp).Value = "Total"
ActiveSheet.Name = "Account13"
Sheets("GL Transaction").Select
ActiveSheet.ListObjects("Account").Range.AutoFilter Field:=3
MsgBox ("Done!")
End Sub
Thank you very much!
Last edited by a moderator: