1

我想按列(rng01)中的值过滤范围(9 列和 1400 行)

Application.ScreenUpdating = False
db.Rows.Hidden = False
For Each cell In rng01.Cells
If Not cell.Value = "323" Then
cell.EntireRow.Hidden = True
End If
Next cell
Application.ScreenUpdating = True

这有效,但大约需要 3-4 秒。
请问有没有更快的方法?

4

1 回答 1

2

Lets see if I understand your question: rng01 is one of the nine columns, you want to filter so that only rows where the value in rng01 = 323 are visible.

You can use AutoFilter for this. You will need a header row above your data (but it can be blank).

rng01.AutoFilter
rng01.AutoFilter Field:=1, Criteria1:="323", VisibleDropDown:=False

If the sheet rng01 referes to already has an active AutoFilter, the first rng01.AutoFilter clears it.

Note that rng01 is one column wide.

If in fact rng01 referes to a range wider than one column, use

rng01.Columns(3).AutoFilter
rng01.Columns(3).AutoFilter Field:=1, Criteria1:="323", VisibleDropDown:=False
于 2012-10-13T07:01:03.763 回答