需要过滤,复制过滤,粘贴到第二个选项卡,然后删除 excel vba 中第一个选项卡上的空行
Need to filter, copy filtered, paste on 2nd tab, and delete the empty rows now on the first tab in excel vba
所以首先我需要过滤我已经在下面的代码中找到的内容。然后我必须将该数据传递到第二个选项卡上。然后我必须从第 1 页删除空行,这样当我取消过滤时,所有内容都会向上移动,这样中间就不会有空白。为了不列出公司信息,我将过滤器值列为 "S"、"T"、"U"、"V"、"W"、"X", "Y", "Z" 这样我就不列出公司信息了。我需要放置到 Sheets(Active Brands") 单元格 A7
Sheets("Active Brands").Select
ActiveSheet.Range("$A:$O3").AutoFilter Field:=8, Criteria1:=Array( _
"S","T","U", "V", "W", "X", "Y", "Z"), Operator:=xlFilterValues
不确定你的问题,但如果问题出在这部分 "Then I must delete the empty rows from page 1 so that when I unfilter everything moves up so there won't be blanks in between. "
然后使用下面的
Range("d3 or whatever your range is ").SpecialCells(xlCellTypeVisible).Delete
*xlCellTypeVisible = 你可以在这里使用很多选项。像 xlcelltype 常量等。只需按 F1 并查看选项
已编辑 以跳过 headers 行
试试这个:
With Worksheets("sheetNameToFilterAndCopyFrom")
With .Range("$A:$O3")
.AutoFilter Field:=8, Criteria1:=Array( _
"S","T","U", "V", "W", "X", "Y", "Z"), Operator:=xlFilterValues
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=Worksheets("sheetNameToPasteTo").Range("A7")destination:=Worksheets("sheetNameToPasteTo").Range("A7")
.SpecialCells(xlCellTypeVisible).Delete
End With
.AutoFilterMode=False
End With
您必须将 "sheetNameToFilterAndCopyFrom" 和 "sheetNameToPasteTo" 更改为您实际相关的工作表名称。
所以首先我需要过滤我已经在下面的代码中找到的内容。然后我必须将该数据传递到第二个选项卡上。然后我必须从第 1 页删除空行,这样当我取消过滤时,所有内容都会向上移动,这样中间就不会有空白。为了不列出公司信息,我将过滤器值列为 "S"、"T"、"U"、"V"、"W"、"X", "Y", "Z" 这样我就不列出公司信息了。我需要放置到 Sheets(Active Brands") 单元格 A7
Sheets("Active Brands").Select
ActiveSheet.Range("$A:$O3").AutoFilter Field:=8, Criteria1:=Array( _
"S","T","U", "V", "W", "X", "Y", "Z"), Operator:=xlFilterValues
不确定你的问题,但如果问题出在这部分 "Then I must delete the empty rows from page 1 so that when I unfilter everything moves up so there won't be blanks in between. "
然后使用下面的
Range("d3 or whatever your range is ").SpecialCells(xlCellTypeVisible).Delete
*xlCellTypeVisible = 你可以在这里使用很多选项。像 xlcelltype 常量等。只需按 F1 并查看选项
已编辑 以跳过 headers 行
试试这个:
With Worksheets("sheetNameToFilterAndCopyFrom")
With .Range("$A:$O3")
.AutoFilter Field:=8, Criteria1:=Array( _
"S","T","U", "V", "W", "X", "Y", "Z"), Operator:=xlFilterValues
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=Worksheets("sheetNameToPasteTo").Range("A7")destination:=Worksheets("sheetNameToPasteTo").Range("A7")
.SpecialCells(xlCellTypeVisible).Delete
End With
.AutoFilterMode=False
End With
您必须将 "sheetNameToFilterAndCopyFrom" 和 "sheetNameToPasteTo" 更改为您实际相关的工作表名称。