Excel过滤宏

时间:2011-09-21 16:11:52

标签: excel vba

我想编写一个宏,它应该像Excel过滤器一样工作。在使用此过滤器获取所有数据后,我想粘贴到新工作表中。

1 个答案:

答案 0 :(得分:1)

此子过滤器在sheet1中为零值并复制到sheet2范围A1

Sub FilterAndCopy()
'Developer by Bruno Leite
'http://officevb.com

Dim Sht As Worksheet
Dim FilterRange As Range

'Set your Sheet
Set Sht = ThisWorkbook.Sheets("Sheet1")
'Verify if is Filter

If Sht.FilterMode Then
      Sht.ShowAllData
End If

'Filter Column A with 0 at parameter
Sht.Range("A:A").AutoFilter Field:=1, Criteria1:="0"

'Define Range Of Visible cells without row title
Set FilterRange = Sht.Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible)

FilterRange.Copy Sheets("Sheet2").Range("A1")

Sht.ShowAllData

End Sub

[]的