+ Reply to Thread
Results 1 to 6 of 6

Stop Macro if Autofilter is Blank

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Stop Macro if Autofilter is Blank

    Greetings, Gurus.

    I am filtering to all columns that have the word "Show" in column 35. In my VBA I need an error trap to exit my VBA if the filter comes back empty. Below is an example of what I attempted, and it did not work because if I offset 1 from A5 it goes to A6 even if the row is hidden.

        Sheets("SPL Pricing by P5").Select
        ActiveSheet.Range("$A$5:$AI$396").AutoFilter Field:=35, Criteria1:="Show"
        Range("A5").Offset(1, 0).Select
        If ActiveCell = 0 Then GoTo NOCHANGE
    Thanks in advance for any help you can offer.

    Hutch
    Last edited by [email protected]; 10-10-2018 at 02:22 PM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Stop Macro if Autofilter is Blank

    Try:
        Sheets("SPL Pricing by P5").Select
        ActiveSheet.Range("$A$5:$AI$396").AutoFilter Field:=35, Criteria1:="Show"
        If Range("A" & Rows.Count).End(xlUp).Row = 5 Then GoTo NOCHAN
    PS. If it's not needed, it's better to use
    if ... then ... else ... end if
    construction then
    if ... then Goto ...
    Best Regards,

    Kaper

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Stop Macro if Autofilter is Blank

    May be this code will help you
    Sub Test()
        Dim rng As Range
    
        Set rng = ActiveSheet.AutoFilter.Range
        
        If rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 > 1 Then
            MsgBox "There are results"
        Else
            MsgBox "No results"
        End If
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: Stop Macro if Autofilter is Blank

    Thanks, Guys. Good advice and results. This thread is solved. Have a good one.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Stop Macro if Autofilter is Blank

    You're welcome. Glad we can offer some help
    Regards

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Stop Macro if Autofilter is Blank

    Glad to hear that too
    Thnx for marking thread SOLVED and for Rep point

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Find Last Row Stop Macro if Cells are blank
    By Tellm in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-08-2017, 06:46 AM
  2. [SOLVED] Blank cell must not stop the macro
    By madmot in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-24-2013, 09:17 AM
  3. [SOLVED] Stop Macro at First Blank Row
    By HappyLadyToo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 10:52 AM
  4. [SOLVED] Autofilter macro once runned, stop and run another macro
    By streamofmight in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2012, 07:08 AM
  5. Stop Macro If Blank
    By id10t in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-18-2011, 09:51 PM
  6. Stop Macro if blank cells are within certain columns
    By superbob in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-07-2010, 08:45 AM
  7. Replies: 2
    Last Post: 04-06-2006, 10:19 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1