Hi
I run this on a test workbook without problems.
Send me your workbook and I take a look at it for you
Sub Copy_With_AdvancedFilter()
Dim ws1 As Worksheet
Dim WSNew As Worksheet
Dim rng As Range
Dim cell As Range
Dim Lrow As Long
Set ws1 = Sheets("Sheet1")
Set rng = ws1.Range("a1:ab64000")
'Use a Dynamic range name,
http://www.contextures.com/xlNames01.html#Dynamic
'This example filter on the first column in the range (change this if needed)
With ws1
rng.Columns(4).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=.Range("IV1"), Unique:=True
'You see that the last two columns of the worksheet are used to make a Unique list
'and add the CriteriaRange.(you can't use this macro if you use this columns)
Lrow = .Cells(Rows.Count, "IV").End(xlUp).Row
.Range("IU1").Value = .Range("IV1").Value
For Each cell In .Range("IV2:IV" & Lrow)
.Range("IU2").Value = cell.Value
Set WSNew = Sheets.Add
On Error Resume Next
WSNew.Name = cell.Value
If Err.Number > 0 Then
MsgBox "Change the name of : " & WSNew.Name & " manually"
Err.Clear
End If
On Error GoTo 0
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("IU1:IU2"), _
CopyToRange:=WSNew.Range("A1"), _
Unique:=False
Next
.Columns("IU:IV").Clear
End With
End Sub
--
Regards Ron de Bruin
http://www.rondebruin.nl
"DoctorV >" <<
[email protected]> wrote in message news
[email protected]...
> Keeps breaking here:rng.Columns(4).AdvancedFilter _
> Action:=xlFilterCopy, _
> CopyToRange:=.Range("IV1"), Unique:=True
>
> Here is the module
>
> Sub Copy_With_AdvancedFilter()
> Dim ws1 As Worksheet
> Dim WSNew As Worksheet
> Dim rng As Range
> Dim cell As Range
> Dim Lrow As Long
>
> Set ws1 = Sheets("MainForm")
> Set rng = ws1.Range("a1:ab64000")
> 'Use a Dynamic range name,
> http://www.contextures.com/xlNames01.html#Dynamic
> 'This example filter on the first column in the range (change this
> if needed)
>
> With ws1
> rng.Columns(4).AdvancedFilter _
> Action:=xlFilterCopy, _
> CopyToRange:=.Range("IV1"), Unique:=True
> 'You see that the last two columns of the worksheet are used to
> make a Unique list
> 'and add the CriteriaRange.(you can't use this macro if you use
> this columns)
> Lrow = .Cells(Rows.Count, "IV").End(xlUp).Row
> Range("IU1").Value = .Range("IV1").Value
>
> For Each cell In .Range("IV2:IV" & Lrow)
> Range("IU2").Value = cell.Value
>
> Set WSNew = Sheets.Add
> On Error Resume Next
> WSNew.Name = cell.Value
> If Err.Number > 0 Then
> MsgBox "Change the name of : " & WSNew.Name & "
> manually"
> Err.Clear
> End If
> On Error GoTo 0
>
> rng.AdvancedFilter Action:=xlFilterCopy, _
> CriteriaRange:=.Range("IU1:IU2"), _
> CopyToRange:=WSNew.Range("A1"), _
> Unique:=False
> Next
> Columns("IU:IV").Clear
> End With
> End Sub
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>