Excel VBA advanced filter to exclude data

0 votes

I'm using customer reference numbers to filter data in a table. Can I filter off rows depending on their customer reference number using a VBA code?

I'm employing a very useful code I saw online that contains information based on a client reference number and looks like this:

Dim rgData As Range, rgCriteria As Range, rgOutput As Range

Set rgData = ThisWorkbook.Worksheets("Sheet 1").Range("A1").CurrentRegion
Set rgCriteria = ThisWorkbook.Worksheets("Sheet 1").Range("I1").CurrentRegion
Set rgOutput = ThisWorkbook.Worksheets("Sheet 2").Range("A1")

rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput

The code first includes just the customers discovered in the table on sheet 1 that begins in cell "I1," then it moves on to sheet 2 and only includes customers in the table that begins in cell "A1" who have customer reference numbers.

Is there a way that I could change the above code so that it excludes those customer reference numbers found in the table in cell "I1"?

Nov 29, 2022 in Others by Kithuzzz
• 27,740 points
96 views

1 answer to this question.

0 votes

Try this:

Sub advanced_filter()

    Dim rgData As Range, rgCriteria As Range, rgOutput As Range
    
    With ThisWorkbook.Worksheets("Sheet 1")
        Set rgData = .Range("A1").CurrentRegion
        Set rgCriteria = .Range("D1").CurrentRegion
        Set rgOutput = .Range("F1")
    
        .Range("F1:G7").ClearContents
        rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput

        Set rgData = .Range("A8").CurrentRegion
        Set rgCriteria = .Range("D8").CurrentRegion
        Set rgOutput = .Range("F8")
    
        .Range("F8:G15").ClearContents
        rgData.AdvancedFilter xlFilterCopy, rgCriteria, rgOutput
    End With
End Sub

enter image description here

answered Dec 10, 2022 by narikkadan
• 51,240 points

Related Questions In Others

0 votes
0 answers

Searching Multiple Criteria In Large Data Set to make new Data Set Excel VBA

My very large data set is updated ...READ MORE

2 days ago in Others by Kithuzzz
• 27,740 points
24 views
0 votes
1 answer

How to import data from a HTML table on a website to excel?

Hello  To import any HTML file in excel there ...READ MORE

answered Feb 10, 2022 in Others by gaurav
• 22,940 points
503 views
0 votes
0 answers

Excel 2010, how to keyboard shortcut to filter dropdown checkboxes?

how do I get to the filter ...READ MORE

Feb 10, 2022 in Others by Edureka
• 13,640 points
77 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
523 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
2,387 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 22,940 points
110 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,640 points
283 views
0 votes
1 answer

How to use data validation and 'no filter' in excel

eventually succeeded in resolving this. Effectively, Filter() ...READ MORE

answered Nov 4, 2022 in Others by narikkadan
• 51,240 points
81 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP