+ Reply to Thread
Results 1 to 4 of 4

if filter criterara misses sub needs to exit

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-04-2016
    Location
    London
    MS-Off Ver
    MS Office Excel 2010/2013
    Posts
    354

    if filter criterara misses sub needs to exit

    Hi all,

    can some one please help me with minute changes to the below code . code should not work if the filter criteria is not available currently it is giving me error if no blanks in the range .

    Sub blamkssss()
    
     ActiveSheet.AutoFilterMode = False
    
        lr = Range("a" & Rows.Count).End(xlUp).Row
    
    
            Range("AC1:AC" & lr).AutoFilter Field:=1, Criteria1:="="
    
            Range("AC2:AC" & lr).SpecialCells(12).EntireRow.Delete
    
            ActiveSheet.AutoFilterMode = False
    
        
    End Sub

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: if filter criterara misses sub needs to exit

    Try this:
    Sub blamkssss()
    
     ActiveSheet.AutoFilterMode = False
        lr = Range("a" & Rows.Count).End(xlUp).Row
            Range("AC1:AC" & lr).AutoFilter Field:=1, Criteria1:="="
            On Error Resume Next
                Range("AC2:AC" & lr).SpecialCells(12).EntireRow.Delete
            On Error GoTo 0
            ActiveSheet.AutoFilterMode = False
    End Sub
    Above is adequate if that is the extent of your code
    But if it's part of something bigger and you want to exit the code if SpecialCells finds no cells, try something like this....
    Sub blamkssss()
    
     ActiveSheet.AutoFilterMode = False
        lr = Range("a" & Rows.Count).End(xlUp).Row
            Range("AC1:AC" & lr).AutoFilter Field:=1, Criteria1:="="
            On Error Resume Next
                Range("AC2:AC" & lr).SpecialCells(12).EntireRow.Delete
                ActiveSheet.AutoFilterMode = False
                    If Err.Number > 0 Then
                        On Error GoTo 0
                        Exit Sub
                    End If
            'rest of your code
    End Sub
    Last edited by kev_; 10-31-2017 at 05:29 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    05-04-2016
    Location
    London
    MS-Off Ver
    MS Office Excel 2010/2013
    Posts
    354

    Re: if filter criterara misses sub needs to exit

    Thank you this is working fine . can i use second method all the time ?.

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: if filter criterara misses sub needs to exit

    Yes you can.
    Thanks for the reps
    Please go to Thread Tools at top of thread and mark thread as SOLVED

+ 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. filter and delet if not then exit sub
    By hudson andrew in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-12-2017, 08:43 AM
  2. VBA - To paste, clear filter then exit sub without displaying error msg
    By sun815613 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2014, 01:16 PM
  3. Macro randomly misses out on a cell.
    By c2q in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2012, 07:14 PM
  4. Chart Zooming Misses Code
    By ant1905 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2012, 09:59 AM
  5. Excel 2007 : Publish as PDF misses shapes
    By davegugg in forum Excel General
    Replies: 9
    Last Post: 10-28-2010, 09:10 PM
  6. How to improve sort - misses some
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2010, 01:04 PM
  7. The Autofilter misses some numbers
    By DaleH in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-05-2006, 07:50 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