PDA

View Full Version : Extract data with one criteria and no duplicate



omegaboost
04-01-2016, 10:19 PM
Dear All,

If i want to exctract data from worksheet "LIST" in column Item with certaint criteria in column Month and show the extracted data with no duplicate in worksheet "ectdata" starting from cell B7, is it possible to do this task with VBA? So everytime we change the criteria in worksheet "ectdata" on cell B4, tha list will be change accordingly.

For more detail I attach the Excel data.

Thank you for your kind helping.

Omegaboost

p45cal
04-02-2016, 04:24 PM
See attached. Change cell B4. You had "Pencil" and "Pencil " (including a space after it) which made it look as if it were producing duplicates; in the attached I removed the trailing spaces.
I moved the Month header from A4 to B3 so that it could be used as Advanced Filter criterion and changed Item List to Item in B6 so that it could be used as a header for Advanced Filter.
The code is in the ectdata sheet's code-module and is:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$4" Then Macro4
End Sub
Sub Macro4()
Sheets("List").Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("ectdata").Range("B3:B4"), CopyToRange:=Sheets("ectdata").Range("B6"), Unique:=True
End Sub

edit post posting: Actually, one line of the code can be a bit shorter:
Sheets("List").Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("B3:B4"), CopyToRange:=Range("B6"), Unique:=True