troubleshooting Question

Filter and Copy

Avatar of Seamus2626
Seamus2626Flag for Ireland asked on
Microsoft Excel
3 Comments1 Solution219 ViewsLast Modified:

I have a piece of code that filters and copyies data.

The problem is when there is no daa to copy, i get the error

"Object Required"

I thought by saying
        If Not rData Is Nothing Then
        Exit Sub

It would leave the sub but it doesnt!

Can anyone advise?

With ActiveSheet
    .AutoFilterMode = False
    .Range("A1").AutoFilter Field:=8, Criteria1:="CA"
    With .AutoFilter.Range
        On Error Resume Next
        Set rData = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If Not rData Is Nothing Then
        Exit Sub
        End If
    End With
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros