Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Dec 2012
    Posts
    58
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Macro for if auto filters dont find a match to not copy data to a new sheet

    Hi Guys,

    The below code runs and the user enters an account number which then goes to the global extract sheet, applies fiters and then copies the data to a new sheet called whatever they entered.

    This macro then goes on to do lots of stuff but the bit i would like to stop is when the macro applys the autofilters, if there is no match then dont do anything, maybe even a message box saying, no records found etc.

    Any ideas?

    Kind regards,


    Ans1 = InputBox("What seibel account number do you wish to generate the statement for?")
    'MsgBox "You will now see all open records for account " & Ans1 & "."


    Sheets("Global Extract").Select
    Range("A1").AutoFilter Field:=2, Criteria1:="=" & Ans1, _
    Operator:=xlAnd

    Application.DisplayAlerts = False
    On Error Resume Next
    Sheets(Ans1).Delete
    On Error GoTo 0
    Application.DisplayAlerts = True


    P.S Happy Christmas all.

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    try:
    Code:
    If Range("A1").currentregion.columns(1).specialcells(xlcelltypevisible).count = 1 then
       msgbox "No matching records"
       Exit sub
    end if
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Star Lounger
    Join Date
    Dec 2012
    Posts
    58
    Thanks
    6
    Thanked 0 Times in 0 Posts
    worked perfect, thanks very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •