I am having difficulty using the “union” within the advanced filter code. I know that the union of the two ranges is set correctly because I can select the union of the two ranges.
I have attached a sample file.
Thanks,
John
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Union of Two Ranges with Advanced Filter (03)
John:
What was the result of the John routine supposed to be?
I was able to eliminate the error by the following modification:
Sub john() On Error GoTo Err_john Dim oWB As String Dim oJoinNewRng01 As Range oWB = Application.ActiveWorkbook.Name Set oJoinNewRng01 = Union(Workbooks(oWB).Sheets("Sheet1").Range("A10:A14"), Range("B10:D14")) oJoinNewRng01.AdvancedFilter Action:=xlFilterCopy, _ CriteriaRange:=Workbooks(oWB).Sheets("Sheet1").Range("Criteria"), _ CopyToRange:=Workbooks(oWB).Sheets("Sheet1").Range("I10:L10"), _ Unique:=False Exit_john: Exit Sub Err_john: MsgBox Err.Number & " - " & Err.Description Resume Exit_john End Sub
I think the solutions are:
1) to setup the data into 1 database and do it directly
2) to do 2 extracts (but you would have to add accounts to the second and then combine them into one list
By “unioning” them the way you do they become 1 database with duplicate column headings and the first ones are pulled
Steve
As Steve remarked in his post 601,062, you can *not* use advanced filter on the union of two ranges:[indent]
By “unioning” them the way you do they become 1 database with duplicate column headings and )only) the first ones are pulled
[/indent](Italics mine)
I’d go with the suggestion by Mike, which is also suggestion 1 by Steve: Combine the two ranges into one, with the data below each other. You then have one contiguous range to work with.
Hans,
As I understand Steve’s comments, the advanced filter can not function with the union of two ranges because of the dupliclate column headings.
Under the senario where a union is made between an account field and data field (no duplicate column headings) would the advanced filter still work?
Within the attached file of my last post, I changed the code to reflect a union between Range(“A10:A14”) and Range(“E10:G14”). Please note that E10 to G10 does not have duplicate column headings.
Thanks,
John
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications