【发布时间】:2017-07-20 21:16:21
【问题描述】:
我在 excel 中有一个 71 列的数据集。在将源工作表(RAS(Offshore))上的自动过滤器应用到目标工作表(Dst)后,我只需要从中复制 7 列。在使用 Excel VBA 将 RAS(Offshore) 上的过滤器应用到 Dst 之后,我需要复制的列是 C,D,G,M,AH,BD,BP。
我成功地应用了自动过滤器并复制了整个范围,但我无法提取如上所述的特定列。请帮忙。
FilterCriteria = InputBox("What text do you want to filter on?", _
"Enter the filter item.")
My_Range.AutoFilter Field:=34, Criteria1:="=" & FilterCriteria
My_Range.AutoFilter Field:=7, Criteria1:="=Freshers/TSS"
With My_Range.Parent.AutoFilter.Range
Set rng = .Offset(1, 0).Resize(.Rows.Count, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
If Not rng Is Nothing Then
'Copy and paste the cells into DestSh below the existing data
rng.Copy
With DestSh.Range("A" & LastRow(DestSh) + 1)
.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
End If
请建议我如何从rng 对象复制C,D,G,M,AH,BD,BP。
【问题讨论】:
-
您可以使用
Union组合所需的列并复制结果,或者复制整个批次然后删除您不需要的列。 -
@SJR 你能建议怎么做吗?
-
Union(Range("C1:C" & intLastRow), Range("D1:D" & intLastRow),...).SpecialCells(xlCellTypeVisible).Copy