【发布时间】:2017-10-02 12:25:23
【问题描述】:
我正在尝试复制然后粘贴到循环中的单元格中。使用单元格 BP3 作为原始参考我试图编写它,以便在每次迭代后它粘贴到从 BP3 向下的下一个单元格中,即 BP4。但我目前只是在单元格 BP4 中重复。
' Copy and Paste of CAPEX 4 forecast dates from VR all DVs
Dim Updated_Spreadsheet As Workbook
Dim wb As Workbook: Set wb = Workbooks("study tracker.xlsm")
Set Updated_Spreadsheet = Workbooks("VR.xlsm")
Set sht = Updated_Spreadsheet.Sheets("Variance Report")
Set sht2 = wb.Sheets("Environmental Studies")
'Loop
Dim cell As Range, lRow As Long, NextRow As Long, lngDataRows As Long
For Each cell In sht2.Range("A3", sht2.Range("A" & Rows.Count).End(xlDown))
'specifying cell i want to use as a criteria for the filter
'cell = sht2.Range("A3").Value
sht.Activate
'specifying filter range
sht.Range("$A$7:$GV$4694").AutoFilter Field:=1, Criteria1:=cell
'specifying the exact cell from the filter which I would like to copy
sht.UsedRange.SpecialCells _
(xlCellTypeVisible).Areas(2).Columns(171).Cells(1, 1).Copy
wb.Activate
'pasting into new location
lngDataRows = cell.CurrentRegion.Rows.Count - 1
Range("BP3").Offset(lngDataRows + 1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next cell
【问题讨论】: