VBA Advanced Filter Question - Definitions needed

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
Hey folks,

I have a large column of info in column D. BUT, there are several duplicates. What I am trying to do is search for the header text, offset that by one row to indicate where the data set actually starts, then filter the duplicates out, caopy the unique records to a new spot and then name the unique range and populate a combo box with them.

BUT, I am having trouble with the "Advanced Filter" code. For some reason I can't get it working, and I wanted to know if someone could define each component of the code so I understand it better..

Could someone help?

Please describe what each of the following are:

xlFilterCopy vs xlFilterInPlace -

CriteriaRange:=

Copy To Range - I think I understand this part, but how do you indicate a named range or a cell on another sheet if you want to move the results?

Unique -


Thanks in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
The options for the first argument kind of do what they say.

xlFilterInPlace - do the filter and show the results in the original location(place)
xlFilterCopy - do the filter and copy the results somewhere else.

You probably want xlFilterCopy.

The 2nd argument is used to specify the range the criteria for the filter is in.

You probably wouldn't need it.

3rd argument, again is what it says - the range you want to copy the results of the filter too.

Unique just tells VBA whether you want to return unique values, so you would want True.

As for specifying a named range for CopyRange, you would do that in the same way you would anywhere else in the code.

So, let's say you want to filter D1:D100 on worksheet 'Data' for duplicates and copy the unique values to a named range called ComboData on sheet 'Lists'.

The code would look something like this:
Code:
Set rngSrc = Worksheets("Data").Range("D1:D100")

Set rngDst = Worksheets("Lists").Range("ComboData").Cells(1)
 
rngSrc.AdvancedFilter Action:=xlFilterCopy, , CopyToRange:=rngDst, Unique:=True
Note I've used the first cell in the named range to avoid any errors.
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

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