使用双variables标准vba的自动filter

所以我需要过滤所有价格小于或等于单元格的值(6,3)(即50.60)。

这是我的代码,但由于某些原因,它只是不适合双值。 例如,如果我将单元格(6.3)的值从50.60更改为50,则代码工作得很好。

有小费吗?

Sub cost() Dim price As Double 'Application.DecimalSeparator = "." 'Application.ThousandsSeparator = "," 'Application.UseSystemSeparators = True Range("B2:C2").Select Range(Selection, Selection.End(xlDown)).Select Selection.NumberFormat = "0.00" price = Cells(6, 3).Value Range("A1:C1").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$C$12").AutoFilter Field:=1, Criteria1:="1" ActiveSheet.Range("$A$1:$C$12").AutoFilter Field:=3, Criteria1:="<=" & price End Sub 

这是我的工作表:

 hour consumption price 1 20,50 0,00 1 50,10 1,30 1 70,60 1,50 1 10,70 30,60 1 15,90 50,60 1 30,80 56,20 1 60,30 60,30 2 45,20 0,00 2 80,60 11,30 2 50,70 20,40 

谢谢您的帮助

这条线对我来说很有效 您只需将price转换为string然后将其连接到"<="

 ActiveSheet.Range("$A$1:$C$12").AutoFilter Field:=3, Criteria1:="<=" & Str(price)