简体   繁体   中英

Excel VBA AutoFilter Percentages

I want to filter a list of industries by using their growth rate as criteria. At the end, I want my sheet just showing industries growing >= 10%.

The data I want to filter is in Tabelle1 Column 10 and is shown as percentage. Furthermore, I have stated my criteria 10% (Which should stay variable) on Tabelle2 Cell B3. However, after exectuing the follwing code it is showing me all industries with a growth rate >= 0%.

Does anyone know why and how I can adjust it to my needs?


Sub AutoFilter()
Dim Bereich As Range
Dim Variable As Long

Set Bereich = Tabelle1.UsedRange
Variable = Tabelle2.Range("B3").Value

Bereich.AutoFilter Field:=10, Criteria1:=">=" & Variable

End Sub

Thank you :)

Your variable needs to be at least float if not double, because eg 12% equals 0.12 .

And .AutoFilter property seems to always expect 'en-US' locale values thus the following code should work:

Sub AutoFilter()
    Dim Bereich As Range, Variable As Double

    Set Bereich = Tabelle1.UsedRange
    Variable = Tabelle2.Range("B3").Value

    Bereich.AutoFilter Field:=10, Criteria1:=">=" & Replace(Variable, ",", ".")
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM