ChloeSpurge
New Member
- Joined
- May 5, 2021
- Messages
- 25
- Office Version
- 2016
- Platform
- Windows
Hi, The bellow code is meant to filter to each value in column J, then copy the data into a new excel tab. However it gets stuck on
Sheets(sht).Range("J1:J" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AN1"), Unique:=True
Any ideas how I could fix it? FYI my data's last column is AM.
Sub filter()
Application.ScreenUpdating = False
Dim x As Range
Dim rng As Range
Dim last As Long
Dim sht As String
'specify sheet name in which the data is stored
sht = "CR Form 2022"
'change filter column in the following code
last = Sheets(sht).Cells(Rows.Count, "J").End(xlUp).Row
Set rng = Sheets(sht).Range("A1:AM" & last)
Sheets(sht).Range("J1:J" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AN1"), Unique:=True
For Each x In Range([AN2], Cells(Rows.Count, "AN").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=10, Criteria1:=x.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
ActiveSheet.Paste
End With
Next x
' Turn off filter
Sheets(sht).AutoFilterMode = False
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub
Many thanks
Sheets(sht).Range("J1:J" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AN1"), Unique:=True
Any ideas how I could fix it? FYI my data's last column is AM.
Sub filter()
Application.ScreenUpdating = False
Dim x As Range
Dim rng As Range
Dim last As Long
Dim sht As String
'specify sheet name in which the data is stored
sht = "CR Form 2022"
'change filter column in the following code
last = Sheets(sht).Cells(Rows.Count, "J").End(xlUp).Row
Set rng = Sheets(sht).Range("A1:AM" & last)
Sheets(sht).Range("J1:J" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AN1"), Unique:=True
For Each x In Range([AN2], Cells(Rows.Count, "AN").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=10, Criteria1:=x.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = x.Value
ActiveSheet.Paste
End With
Next x
' Turn off filter
Sheets(sht).AutoFilterMode = False
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
End Sub
Many thanks