+ Reply to Thread
Results 1 to 5 of 5

Skip Section of Code if Filter Returns a Blank

Hybrid View

tamiso2311 Skip Section of Code if... 02-08-2013, 03:02 AM
AlphaFrog Re: Skip Section of Code if... 02-08-2013, 03:25 AM
tamiso2311 Re: Skip Section of Code if... 02-10-2013, 06:55 PM
JBeaucaire Re: Skip Section of Code if... 02-08-2013, 03:34 AM
JBeaucaire Re: Skip Section of Code if... 02-11-2013, 12:53 AM
  1. #1
    Registered User
    Join Date
    02-08-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Skip Section of Code if Filter Returns a Blank

    I have a spreadsheet which will collect a large amount of data throughout the year that I need to report on Monthly. However at present there is very little in there.
    I have written into my macro for it to copy select data remaining from three columns after 3 filters have been applied into another sheet. (the filters contain data from drop down lists so there is no possibility of anyone entering incorrect information.)

    The problem I am having is that if the applied filters return a blank the macro copies and pastes the entire column within the specified datarange. Can anyone assist me in some sort of If/Else statement that will have it do nothing if the filter returns a blank and move onto the next section of code.
    I have included the problem code below.

    Sheets("2013 EOI_Tender").Select
        ActiveSheet.Range("$A$7:$AT$55").AutoFilter Field:=7, Criteria1:="Jan"
        ActiveSheet.Range("$A$7:$AT$55").AutoFilter Field:=4, Criteria1:="Tender"
        ActiveSheet.Range("$A$7:$AT$55").AutoFilter Field:=5, Criteria1:= _
        "Successful"
    
    "This is where it is returning a blank result.  I want it to stop from processing the next bit of code, and move onto another process in the macro"
    
    Sheets("2013 EOI_Tender").Select
        ActiveSheet.Range("C8:C55").Select
        Selection.Copy
        Sheets("Monthly Report").Select
        Range("A9").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    Last edited by JBeaucaire; 02-08-2013 at 03:31 AM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Skip Section of Code if Filter Returns a Blank

    This will test if there is any visible rows with data in column A below row 7

    Sheets("2013 EOI_Tender").Select
    If Range("A" & Rows.Count).End(xlUp).Row > 7 Then
        ActiveSheet.Range("C8:C55").Select
        Selection.Copy
        Sheets("Monthly Report").Select
        Range("A9").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    End If

  3. #3
    Registered User
    Join Date
    02-08-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Skip Section of Code if Filter Returns a Blank

    Thank you, problem solved.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Skip Section of Code if Filter Returns a Blank

    Same solution as AlphaFrog, but I can't leave all that "selecting" in there:

    Dim LR As Long
    
    With Sheets("2013 EOI_Tender")
        .Range("$A$7:$AT$55").AutoFilter Field:=7, Criteria1:="Jan"
        .Range("$A$7:$AT$55").AutoFilter Field:=4, Criteria1:="Tender"
        .Range("$A$7:$AT$55").AutoFilter Field:=5, Criteria1:="Successful"
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        If LR > 7 Then
            .Range("C8:C" & LR).Copy
            Sheets("Monthly Report").Range("A9").PasteSpecial xlPasteValues
        End If
        .AutoFilterMode = False
    End With
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Skip Section of Code if Filter Returns a Blank

    I have marked this thread solved for you.
    In the future please select Thread Tools from the menu above and mark the thread as solved. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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