ozalonazol
New Member
- Joined
- Jun 8, 2017
- Messages
- 2
Hi! My VBA knowledge is very basic so I am really lost about how to solve my problem. I am trying to filter values from a large dataset, copy them and paste them to a new sheet. I found a code in an old threat https://www.mrexcel.com/forum/excel...ications-autofilter-copy-paste-new-sheet.html which i tried to use but it hasn't worked. The code I am using is the following and the error I get is "Run-time error '1004': The extract range has a missing or invalid field name". My data is in the range A1:BH3921 and column A contains the unique values that I want to filter. There are multiple rows containing each value.
Could you please help me to find the error or suggest another code that serves for the same purpose?
Thanks in advance for your help!
Could you please help me to find the error or suggest another code that serves for the same purpose?
Thanks in advance for your help!
Code:
Sub Foo()
Dim c As Range
Dim rng As Range
Dim LR As Long
LR = Cells(Rows.Count, "R").End(xlUp).Row
Set rng = Range("A1:BH" & LR)
Range("A1:A" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AM1"), Unique:=True
For Each c In Range([AM2], Cells(Rows.Count, "AM").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=1, Criteria1:=c.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
ActiveSheet.Paste
End With
Next c
End Sub