VBA code to exclude filtered data from multiple columns and paste remaining data into another worksheet

WWII_Buff

Board Regular
Joined
Nov 13, 2017
Messages
88
Macro Recorder gave me an error that I selected too many criteria in my attempt, so I am stumped yet again.

I need help in writing a macro that applies filters on Row 4 on the "Master" sheet and exclude the following items below

Code:
Sub Test8()

    Rows("4:4").Select
    Selection.AutoFilter
  
  ActiveSheet.Range("$A$4:$BB$15334").AutoFilter Field:=2, Criteria1:=Array( _
        "0", "99999", "TOTAL ENERGY", "TOTAL EXPENSE", "TOTAL LABOR", _
        "TOTAL LABOR & EXPENSE", "TOTAL START UP", "TOTAL VOLUME", "TOTAL WASTE"), _
        Operator:=xlFilterValues
   
  ActiveSheet.Range("$A$4:$BB$15334").AutoFilter Field:=7, Criteria1:="=G&A" _
        , Operator:=xlOr, Criteria2:="="
   
  ActiveSheet.Range("$A$4:$BB$15334").AutoFilter Field:=52, Criteria1:="-"
End Sub

With the remaining data, copy (starting from Row 5) Columns A, B and AM:AY and paste to the "UPLOAD TEMPLATE" worksheet that is already created starting in A6.
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Is row 4 your header row & does it have values in every column from A to BB?
Also what errors are you getting & on what line of code.
 
Upvote 0
@Fluff Thank you thank you thank you!

Yes, Row 4 are headers and they do have values from A to BB

They error code I received said I selected too many items here.
Code:
  ActiveSheet.Range("$A$4:$BB$15334").AutoFilter Field:=52, Criteria1:="-"
which was an attempt of grabbing non-blank rows.
 
Last edited:
Upvote 0
What if you put that line 1st, do you still get the error?
 
Upvote 0
I will give that a shot!

Here is what I have so far - but I get an error at the 1st ActiveSheet.Range:

Code:
Sub Upload()


    Dim src As Worksheet
    Dim trg As Worksheet
    Dim LastRow As Long




    Set src = ThisWorkbook.Worksheets("MASTER")
    Set trg = ThisWorkbook.Worksheets("UPLOAD TEMPLATE")
    
    Sheets("MASTER").Select
    Rows("4:4").Select
    Selection.AutoFilter
    
    ActiveSheet.Range("$A4:BB" & LastRow).AutoFilter Field:=2, Criteria1:=Array( _
        "<>0", "<>99999", "<>*TOTAL*"), _
        Operator:=xlFilterValues
        
    ActiveSheet.Range("$A4:BB" & LastRow).AutoFilter Field:=7, Criteria1:="<>G&A" _
        , Operator:=xlOr, Criteria2:="<> "
        
    ActiveSheet.Range("$A4:BB" & LastRow).AutoFilter Field:=52, Criteria1:="<>-"


    LastRow = src.Cells(Rows.Count, 1).End(xlUp).Row


    src.Range("A5:A" & LastRow).SpecialCells(xlCellTypeVisible).Copy Destination:=trg.Range("A6")
    src.Range("B5:B" & LastRow).SpecialCells(xlCellTypeVisible).Copy Destination:=trg.Range("B6")
    src.Range("AM5:AY" & LastRow).SpecialCells(xlCellTypeVisible).Copy Destination:=trg.Range("C6")


End Sub
 
Upvote 0
I will give that a shot!

Here is what I have so far - but I get an error at the 1st ActiveSheet.Range:
That's because LastRow does not have a value.
Also that code won't work as you can only filter on 2 <> values.

If on col AZ you want to get all non blanks then try
Code:
Criteria1:="<>"
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top