我想使用与此处相同的宏: Copy/Paste/Calculate Visible Cells from One Column of a Filtered Table
但我需要将数据复制到第一个空单元格,而不是A1。
请参阅下面的我目前的代码:
Sub fromreport()
Const fromFile = "c:\Users\asobczyk\Desktop\Report.xls"
Dim srcBook As Workbook
Set srcBook = Application.Workbooks.Open(fromFile, _
UpdateLinks:=False)
Application.ScreenUpdating = False
srcBook.Sheets("Test Invoice Report").Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ActiveSheet.Name = "report"
srcBook.Close False
Dim src As Worksheet
Dim tgt As Worksheet
Dim filterRange As Range
Dim copyRange As Range
Dim lastRow As Long
Set src = ThisWorkbook.Sheets("report")
Set tgt = ThisWorkbook.Sheets("One")
src.AutoFilterMode = False
lastRow = src.Range("A" & src.rows.Count).End(xlUp).Row
Set filterRange = src.Range("A8:J" & lastRow)
Set copyRange = src.Range("B9:J" & lastRow)
filterRange.AutoFilter field:=1, Criteria1:="EN > One"
copyRange.SpecialCells(xlCellTypeVisible).Copy tgt.Range("B3")
Application.DisplayAlerts = False
Worksheets("report").Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = False
End Sub
最诚挚的问候,