简体   繁体   English

以变​​量/单元格为标准的自动过滤器

[英]Autofilter with variable/cell as Criteria

I want to use autofilter function but I want to take the Criteria1 from the cell from another Worksheet. 我想使用自动过滤功能,但我想从另一个工作表的单元格中获取Criteria1。 I tried to use the the exact range and also a variable. 我试图使用确切的范围,也是一个变量。 I become the error run time error 9 subcript out of range by the line. 我的错误运行时错误9被行超出了范围。 Set GL = Worksheets("Sheet1").Range("l7").Value. 设置GL = Worksheets(“ Sheet1”)。Range(“ l7”)。Value。 Is it even possible? 可能吗 Should I use another type of variable? 我应该使用其他类型的变量吗? At the beggining I am in worksheet("DE-CC") and the criteria I take from Worksheet("Sheet1"), cell "L7". 在开始时,我位于工作表(“ DE-CC”)中,而我从工作表(“ Sheet1”)的单元格“ L7”中获取标准。 Any sugestions? 有任何建议吗?

Dim GL As Range
Set GL = Worksheets("Sheet1").Range("l7").Value
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("AB1").Select
    Selection.AutoFilter
    ActiveSheet.Range("a2:ab2").AutoFilter Field:=19, Criteria1:=GL

This should Work: 这应该工作:

(Untested) (未经测试)

Dim GL As String

GL = Worksheets("Sheet1").Range("l7").Value

    Rows("1:1").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Activesheet.UsedRange.AutoFilter Field:=19, Criteria1:=GL

Changed the Declaration and assigning of Value 更改了声明和价值分配

You should Try this Also, 您也应该尝试一下

Dim GL As String

GL = Worksheets("Sheet1").Range("l7").Value

    Activesheet.UsedRange.AutoFilter Field:=19, Criteria1:=GL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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