2011-09-21 114 views
0

我想写一个宏,它应该像Excel过滤器一样工作。在使用这个过滤器获得所有数据后,我想粘贴到新的工作表中。在Sheet1和副本Excel过滤器宏

+0

你应该尝试拍摄这样的事情宏。然后调整适合的代码。 – Reafidy

回答

1

此子滤波器零值到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 

[]的