autofilter raises error 1004
You're absolutely right!
Thanks for the correction, OssieMac.
OssieMac wrote:
You are correct Dave in not allowing VBA to guess, particularly with
autofilter, because who knows what the user has been doing before running the
code.
However, in testing your code I found that need to turn off autofilter
before finding the last row otherwise last row will always be the last
visible row of the autofiltered data and not necessarily the last row of data.
Sub af3()
Dim LastRow As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
With ws
.AutoFilterMode = False
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("A1:D" & LastRow).AutoFilter field:=1, _
Criteria1:="", visibledropdown:=False
End With
End Sub
--
Regards,
OssieMac
--
Dave Peterson
|