有人可以帮我解决这个问题吗?它在粘贴阶段分解。
Sub GetFileCopyLabour()
Dim Fname As String
Dim SrcWbk As Workbook
Dim DestWbk As Workbook
Dim lDestLastRow As Long
Set DestWbk = ThisWorkbook
Fname = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*", Title:="Select a File")
If Fname = "False" Then Exit Sub
Set SrcWbk = Workbooks.Open(Fname)
lDestLastRow = DestWbk.Sheets("Labour Dump").Cells(DestWbk.Sheets("Labour Dump").Rows.Count, "A").End(xlUp).Offset(1).Row
SrcWbk.Sheets("DATA DUMP").Range("A:AX").Copy DestWbk.Sheets("Labour Dump").Range("A:AX" & lDestLastRow)
SrcWbk.Close False
End Sub
答案 0 :(得分:0)
这对我有用:
Sub GetFileCopyLabour()
Dim Fname As String
Dim SrcWbk As Workbook
Dim DestWbk As Workbook
Dim lDestLastRow As Long
Dim SrcWbkLastRow As Long
Set DestWbk = ThisWorkbook
Fname = Application.GetOpenFilename(FileFilter:="Excel Files (.xls), .xls", Title:="Select a File")
If Fname = "False" Then Exit Sub
Set SrcWbk = Workbooks.Open(Fname)
lDestLastRow = DestWbk.Sheets("Labour Dump").Cells(DestWbk.Sheets("Labour Dump").Rows.count, "A").End(xlUp).Offset(1).row
SrcWbkLastRow = SrcWbk.Sheets("DATA DUMP").Cells.Find(what:="*", After:=SrcWbk.Sheets("DATA DUMP").Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).row
SrcWbk.Sheets("DATA DUMP").Range("A1:AX" & SrcWbkLastRow).Copy
DestWbk.Sheets("Labour Dump").Range("A" & lDestLastRow).PasteSpecial
SrcWbk.Close False
End Sub
答案 1 :(得分:0)
这是我修改后的代码,除了粘贴特殊值后开始的两行外,它工作正常。我正在尝试在单元格AY2和AZ2中获取公式,以复制新数据范围的整个列,但目前,它仅对第一行进行此操作。你知道怎么解决吗?有问题的代码位于双星号中,这不是原始代码的一部分!
Sub GetFileCopyLabour()
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.AskToUpdateLinks = False
Application.Calculation = False
Dim Fname作为字符串 昏暗的SrcWbk作为工作簿 Dim DestWbk作为工作簿 昏暗的lDestLastRow只要
Set DestWbk = ThisWorkbook
Fname = Application.GetOpenFilename(FileFilter:="Excel Files (.xls), .xls", Title:="Select a File")
If Fname = "False" Then Exit Sub
Set SrcWbk = Workbooks.Open(Fname)
lDestLastRow = DestWbk.Sheets("Labour Dump").Cells(DestWbk.Sheets("Labour Dump").Rows.Count, "A").End(xlUp).Offset(1).Row
SrcWbk.Sheets("DATA DUMP").Range("A2:AX2000").Copy
DestWbk.Sheets("Labour Dump").Range("A" & lDestLastRow).PasteSpecial xlPasteValues
**DestWbk.Sheets("Labour Dump").Range("AY2:AZ2").Copy
DestWbk.Sheets("Labour Dump").Range("AY2:AZ" & lDestLastRow).FillDown**
SrcWbk.Close False
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.AskToUpdateLinks = True
Application.Calculation = True
结束子