Solved

Error Handler

Posted on 2012-04-11
2
274 Views
Last Modified: 2012-06-27
Hi,

I have the below code.

When there is no closed Items, so the filter returns blank, i want to exit the sub with a message box saying "No closed Items"

Can someone advise where i would slot this in?

Thanks
Seamus








Private Sub CommandButton1_Click()

Dim rData As Range

Application.ScreenUpdating = False

With ActiveSheet
    .AutoFilterMode = False
    .Range("A1").AutoFilter Field:=12, Criteria1:="Closed"
    With .AutoFilter.Range
        On Error Resume Next
        Set rData = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
        On Error GoTo ErrHandler
        If Not rData Is Nothing Then
            rData.EntireRow.copy
        End If
           

    End With
 
End With
 
Call copyOver
 
Application.ScreenUpdating = False





End Sub
0
Comment
Question by:Seamus2626
2 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 37831975
Seamus - try this:
Private Sub CommandButton1_Click()

Dim rData As Range

Application.ScreenUpdating = False

With ActiveSheet
    .AutoFilterMode = False
    .Range("A1").AutoFilter Field:=12, Criteria1:="Closed"
    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
            rData.EntireRow.Copy
        Else
            MsgBox "No closed items"
            Exit Sub
        End If
    End With
End With
 
Call copyOver
 
Application.ScreenUpdating = False

End Sub

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 37832008
Thanks Stephen!

Seamus
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question