Unique Filter Macro (Ignore Zeros)

lewis1

Board Regular
Joined
Jul 20, 2009
Messages
81
Hi,

My data is a column of zero's and dates.

I have a basic unique filter macro to filter the dates. However, the first two results of the filter are two 'zero's. Could you please help me adjust the formula so that it ignores the zero's.

Code:
Sub UniqueFilter()


Range("D10:D1258").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("E10"), Unique:=True


End Sub

PS:
I am also open to a formula which can do the job, however, given the number of rows I have found that any formula is very slow.

Kind regards,
Lewis.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
sample data like this

Excel Workbook
ABCDE
1hdng1hdng1
200
30
41
52
63
72
81
91
102
113
Sheet1



try this macro (use this for your data)

Code:
 Range("A1:A11").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "E1:E2"), CopyToRange:=Range("A14"), Unique:=True
 
Upvote 0
Hi,

Thanks very much. I attempted to add the code. However, it did not work for me. Now, the code is simply returning only zero....
 
Upvote 0
see if this change to your code helps. I have set the CriteriaRange to B1:B2 on your worksheet - amend as required.

Code:
Sub UniqueFilter()
    'add criteria
    'assumes D10 is a heading
    Range("B1").Value = Range("D10").Value
    'set filter
    Range("B2").Value = "<>0"
    
    
    Range("D10:D1258").AdvancedFilter Action:=xlFilterCopy, _
                                      CriteriaRange:=Range("B1:B2"), _
                                      CopyToRange:=Range("E10"), _
                                      Unique:=True
End Sub

Dave
 
Upvote 0
Thanks very much. I attempted to add the code. However, it did not work for me. Now, the code is simply returning only zero....

where did you park the macro. how did you run the macro

after running macro the sheet will be like this see A14 down

Sheet1

*ABCDE
1hdng1 hdng1
20 <>0
30
41
52
63
72
81
91
102
113
12*****
13*****
14hdng1****
151****
162****
173****

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
Hi,

Thanks for your help. I guess I didn't explain how my data should come out. It appears your results are slightly more elaborate than what i am looking.

Given your data above, I am simply looking for the unique data from Range(A1:A11) to paste in cell C1 for example, and that none of the zero's be included in the unique results.

Apologies, I am not sure what the 2 headings you have in your column A are and all the stars...
 
Upvote 0
main data is from A1 to A11

the result of the advance filter is in

A14 and down.(unique values except 0)

crieria for advanced filter without zero is E1:E2

the stars are blanks.
you can copy A14 anywhere you like
slternatively you can define "copy to rangae:=<change A14 to any o;ther cell)

I do not like to copy the reslt within the data rows sometimes filtered data may give problem particularly if it is autofilter.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,165
Members
449,295
Latest member
DSBerry

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