我想知道如何将VBA语句写入
答案 0 :(得分:0)
尝试下面的代码(将“Sheet6”修改为工作表的名称):
Option Explicit
Sub CopyFiltResults()
Dim FiltRng As Range
With Worksheets("Sheet6") ' modify "Sheet6" to your sheet's name
With .Range("A1:J" & .Cells(.Rows.Count, "I").End(xlUp).Row)
' set range filter column I to "Gross Sale"
.AutoFilter Field:=9, Criteria1:="Gross Sale"
Set FiltRng = .Columns(9).SpecialCells(xlCellTypeVisible)
FiltRng.Copy .Range("K1") '<-- only copy visible cells to Column K
Set FiltRng = Nothing '<-- clear range variable
' set range filter column I to "Net Sales"
.AutoFilter Field:=9, Criteria1:="Net Sales"
Set FiltRng = .Columns(9).SpecialCells(xlCellTypeVisible)
FiltRng.Copy .Range("L1") '<-- only copy visible cells to Column L
End With
End With
End Sub