我正在尝试过滤不为空的列,但是不适用于以下代码:
ActiveSheet.Range("A:FE").AutoFilter Field:=12, Criteria1:="<>", Operator:=xlOr
另外请注意,标题顶部有6行,我不能出于其他目的将其删除
我不知道会不会影响编码
答案 0 :(得分:1)
如果前6行为空白,则不要过滤A:FE
。构建范围,然后对其进行过滤。我猜您想对Col L(字段:= 12)进行过滤?
尝试一下
Option Explicit
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long
Dim rng As Range
Set ws = Sheet1 '<~~ Change this to the relevant sheet
With ws
.AutoFilterMode = False
'~~> Assuming that Col A will have all cells filled up
'~~> Else change this to the relevant column or use .Find
'~~> to find the last row
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
'~~> Construct your range
Set rng = Range("A7:FE" & lRow)
'~~> Filter it
rng.AutoFilter Field:=12, Criteria1:="<>"
End With
End Sub