我有5个不同的文件(全部在同一个文件夹中),其中一个我用它作为主/报告工作簿,其他是代理填充信息的地方,在主文件中我有几张我要粘贴信息在名为Consolidated的工作表中,所有其他文件只有1个工作表(Sheet1),复制信息的范围是相同的(A2:AP1779)。
我正在尝试一种方法,例如(请注意评论)
Sub cnsldt()Dim FilePath As String
Dim FileName As String
Dim iRow As Long
Dim lCell as Range
FilePath = "Z:\Lead Generation\Jose Buitrago\Special Projects-Asignments\Data Gap Project\"
FileName = "Data Gap Project High Priority 2016 - "
iRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row
'First we clear the sheet where I'm going to paste the info
Set lCell = Sheets("Consolidated").Cell(iRow,AP)
Range("A2",lCell).ClearContents
'not sure if must open files or just copy the info
'not sure if should unhide Column A
'AgentTest not declared because that is the name of the file so in this example the target is Z:\Lead Generation\Jose Buitrago\Special Projects-Asignments\Data Gap Project\Data Gap Project High Priority 2016 - AgentTest.xslx
Workbooks("FilePath & FileName & AgentTest.xslx").Sheets("Sheet1").Range("A2:AP1779").Copy
Workbooks("FilePath & Data Gap Project High Priority 2016.xslx").Sheets("Consolidated").Range("A2").PasteSpecial xlPasteValuesApplication.CutCopyMode = False
'How should I proceed afterwards since the paste range its not A2 it would be Cell(iRow+1,A) ?
End Sub
我对如何解决这个问题抱有很多怀疑。
答案 0 :(得分:0)
尝试使用以下
Workbooks(FilePath & "Data Gap Project High Priority 2016.xslx").Sheets("Consolidated").Range ("A" & iRow + 1)
编辑1
未经测试。但请尝试使用以下代码。
Sub cnsldt()
Dim FilePath As String
Dim FileName As String
Dim iRow As Long
Dim lCell As Range
FilePath = "Z:\Lead Generation\Jose Buitrago\Special Projects-Asignments\Data Gap Project\"
FileName = "Data Gap Project High Priority 2016 - "
Workbooks.Open (FilePath & FileName & "AgentTest.xslx")
iRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
'First we clear the sheet where I'm going to paste the info
Set lCell = Sheets("Consolidated").Cell(iRow, AP)
Range("A2", lCell).ClearContents
'not sure if must open files or just copy the info
'not sure if should unhide Column A
'AgentTest not declared because that is the name of the file so in this example the target is Z:\Lead Generation\Jose Buitrago\Special Projects-Asignments\Data Gap Project\Data Gap Project High Priority 2016 - AgentTest.xslx
Workbooks(FilePath & FileName & "AgentTest.xslx").Sheets("Sheet1").Range("A2:AP1779").Copy
Workbooks(FilePath & "Data Gap Project High Priority 2016.xslx").Sheets("Consolidated").Range("A2").PasteSpecial xlPasteValuesApplication.CutCopyMode = False
Workbooks(FilePath & "Data Gap Project High Priority 2016.xslx").Sheets("Consolidated").Range ("A" & iRow + 1)
'How should I proceed afterwards since the paste range its not A2 it would be Cell(iRow+1,A) ????
End Sub