vba将筛选的行复制到另一sheet页,并在原sheet页删除筛选的内容
时间: 2023-03-27 19:01:45 浏览: 234
可以使用以下代码实现:
Sub CopyFilterRows()
Dim wsSource As Worksheet, wsDest As Worksheet
Dim rngFilter As Range, rngCopy As Range
Dim lastRow As Long
'设置源表和目标表
Set wsSource = ActiveSheet
Set wsDest = Sheets("目标表")
'获取筛选范围
Set rngFilter = wsSource.Range("A1").CurrentRegion
'筛选数据
rngFilter.AutoFilter Field:=1, Criteria1:="筛选条件"
'获取筛选后的数据范围
lastRow = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
Set rngCopy = wsSource.Range("A2:A" & lastRow).SpecialCells(xlCellTypeVisible)
'将筛选后的数据复制到目标表
rngCopy.Copy wsDest.Range("A1")
'在源表中删除筛选的内容
rngFilter.Offset(1, ).Resize(rngFilter.Rows.Count - 1, rngFilter.Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow.Delete
'取消筛选
rngFilter.AutoFilter
End Sub
阅读全文