Solved

Error Handler

Posted on 2012-04-11
2
271 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
Comment Utility
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
Comment Utility
Thanks Stephen!

Seamus
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now