Great Difficulty Getting Results From VBA Advanced Filter

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am simply trying to filter data according to my advanced criteria range in worksheet "ws_fac" (in 2nd workbook) and copy it over to a range starting at AN3 in worksheet "ws_lists" (of 1st primary code holding workbook)

Here is the code I'm struggling with:
Rich (BB code):
If ws_fac.FilterMode Then ws_fac.ShowAllData                                              'turn off any filtering if data is filtered
ws_lists.Range("AN3").CurrentRegion.Offset(1).ClearContents                      'clear the destination range (filtered data to be copied here)
Set rgData = ws_fac.Range("A1").CurrentRegion                                           'define the source range (all data in ws_fac including header row 1)
Set rgCriteriaRange = ws_lists.Range("AI2:AJ3").CurrentRegion                   'criteria range (AI3 AND AJ3)
Set rgCopyToRange = ws_lists.Range("AN3").CurrentRegion.Rows(1)          'destination target (ws_lists starting at AN3)
rgData.AdvancedFilter xlFilterCopy, rgCriteriaRange, rgCopyToRange        'apply filter
lrfaclst = ws_lists.Cells(ws_lists.Rows.Count, "AN").End(xlUp).Row                'get the value of the last row of copied data range
ws_lists.Range("AN" & lrfaclst + 1) = "Nothing suitable."                             'add a value to the end of the column of data


The line in red is giving me a "The extract range has a missing or invalid field name." I'm unsure why. The column headers match the reference headers in my data. All the columns in my source data have a header label, and no column is without a header label.

Here is the structure of my source data worksheet:
Facilities.xlsx
ABCDEFGHIJKLMNOPQR
1hh FIELD (do not alter)AN RESOURCE TYPECLASSRESPTYPEUNITLITLABELWashroomWR_CodeFAMILYWP_SideGROOMACT-PASSCONFIGGOALSPARKAddress
2hhhhhhhhhhhhhhhhhhhhhhhhBBPhhhh1NhhhhhhhhhhhhhhhhhNxBPCRPAhhhh
3lllllllllllllllllABPllll1YlllllllllllllllYxBPCRPAlllll
4mmmmmmmmmmmmmmmmBBPField1NmmmmmmmmmNxBPnaANCNAmmm
5mmmmmmmmmmmmmmmmABPField2YmmmmmmmmmNxBPnaAS1 90m x 61.5mNAmmm
Facilities


Here is my criteria range:
SignatureSheets.xlsm
AIAJ
1Advanced Filter1
2ACT-PASSLABEL
3PWP*
lists


And finally, the structure of my destination:
SignatureSheets.xlsm
ANAO
1FacList
2ACT-PASSLABEL
3
4
5
6
lists


I don't yet quite understand VBA based advanced filtering so I'm struggling to figure out where I need to make corrections. Be very grateful for any one that can offer up some advice, solutions.
 
Wonderful! Starting to get greater clarity on some of the functions I've been scared to use. Basic tutorials are good, but I find that sometimes my needs are unique and although the concept is the same, it's difficult to relate to adjust accordingly. Practice makes perfect!
Offset by rows moves the whole range area you are working with down by that no of rows.
So Range("A10:E13").Offset(5) becomes Range("A15:E18").
Perhaps still not grasping it, but wouldn't Range("A10:E13").Offset(5) become Range("A15:E13")? Or does just the one value of Offset change both the row and column by that same number?
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
A10:E15 is a block of cells 5 by 5.
Offset by 5 rows moves the whole block down 5 rows.
So you still have a block of 5 by 5 just 5 rows further down the sheet.
So just to get away from all the 5s, if the block was say 4x3 it would stay 4x3 just the offset no of rows further down
 
Upvote 0
Ahhh! Got it! I think it's that that got me all messed up when I've played with offset before.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

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