Currently, I am doing a report which contains lots of data and I need to filter out each unique account and copy& paste the data to a new/current tab.
Looking to see if someone can help me on this. I will be very appreciate.
What I want the code is to help me to filter each unique account numbers and copy and paste the new/current , so every time I update the "Summary" table and I just need to run the code, and it will do the job for me.
My current code can filter those accounts and create a new tab for each unique account. However, if I update the "Summary" table, the code could not run due to the tab is already existed.
Here is the current code I got so far:
Sub filter()
Application.ScreenUpdating = False
Dim x As Range
Dim rng As Range
Dim last As Long
Dim sht As String
sht = "Summary"
last = Sheets(sht).Cells(Rows.Count, "T").End(xlUp).Row
Set rng = Sheets(sht).Range("A1:T" & last)
Sheets(sht).Range("T1:T" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
For Each x In Range([AA2], Cells(Rows.Count, "AA").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=20, Criteria1:=x.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
ActiveSheet.Paste
End With
Next x
Sheets(sht).AutoFilterMode = False
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub
Looking to see if someone can help me on this. I will be very appreciate.
What I want the code is to help me to filter each unique account numbers and copy and paste the new/current , so every time I update the "Summary" table and I just need to run the code, and it will do the job for me.
My current code can filter those accounts and create a new tab for each unique account. However, if I update the "Summary" table, the code could not run due to the tab is already existed.
Here is the current code I got so far:
Sub filter()
Application.ScreenUpdating = False
Dim x As Range
Dim rng As Range
Dim last As Long
Dim sht As String
sht = "Summary"
last = Sheets(sht).Cells(Rows.Count, "T").End(xlUp).Row
Set rng = Sheets(sht).Range("A1:T" & last)
Sheets(sht).Range("T1:T" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AA1"), Unique:=True
For Each x In Range([AA2], Cells(Rows.Count, "AA").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=20, Criteria1:=x.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
ActiveSheet.Paste
End With
Next x
Sheets(sht).AutoFilterMode = False
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub