Home » excel » How to automatically create filtered list from Excel dataset using VBA?

How to automatically create filtered list from Excel dataset using VBA?

Posted by: admin May 14, 2020 Leave a comment


I got a problem with Excel 2007 where I cannot find a solution to. I think one has to use VBA to do it by I am pretty unexperienced with that.
I have a dataset in Excel (about 1k lines) with 10 columns. In an other tab/worksheet, I now want to display the data filtered by one column (country codes). It can be done dirty with autofiltering but it should be more like a report so it has to look good.

Let me make an example what I mean:


Column | Column 2 | Column 3

Hans | GER | 16

Peter | US | 29

Maria | GER | 30

Darian | US | 15

Lisa | GER | 40

In an other Tab/Worksheet, I now want an automatically updated, formatted and filtered list based on this data set, e.g.:



Hans | 16

Maria | 30

Lisa | 40


Peter | 29

Darian | 15

I hope you understand what I mean. If I add new lines of data in my dataset sheet, I want the report to be automatically updated (so I can’t just but autofilter lists below each other because the number of rows which will be needed depends on the data points). I think this should be pretty easy to do using a VBA macro, but I have no clue how to do it… Help very much appreciated!

Thanks upfront!


How to&Answers:

Have you tried a PivotTable combined with a dynamic named range?

Given your data set above is set up in Sheet1 of your workbook, starting in A1 with column names. See the following solution.

1) Enter a dynamic named range for your dataset, like below.

enter image description here

This will ensure that any new data that is added to the end, or inserted into the middle of the data set gets captured and updated automatically with a pivot table refresh.

2) Base your pivot table on the Named Range.

enter image description here

3) Finally, set up your PivotTable like below.

enter image description here

You can then format your pivot table how you like.


A Pivot table can do the type of grouping you are looking for. Using the data you provided, this is what I get from a pivot table:

enter image description here


I suggest you take a look at pivot tables. they can be a bit complicated but once you figure out how they work they are very useful.