我正在尝试将 sheet1 范围数据复制到 sheet2 范围,但没有复制任何内容。这是我试图实现某些目标但卡在基本位置的完整代码。请帮忙
编辑:我刚刚尝试了宏,这段代码也发生了同样的事情。请查看快照,您可以在其中看到 Snap 1 包含源数据并且也被选中,但没有被复制到 Snap 2。但是在那里选择了范围。
Sub copy()
Range("A1:J4").Select
Selection.copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWorkbook.Save
End Sub
更新
样式-1
Option Explicit
Dim objSheet1,objSheet2,TotalRows,TotalcolCopy,strPathExcel1
Dim oXls : Set oXls = CreateObject("Excel.Application")
Dim aData ': aData = oWb.Worksheets(1).Range("$A2:$C10")
Dim dicP : Set dicP = CreateObject("Scripting.Dictionary")
strPathExcel1 = "D:\WIPData\AravoMacro\Finalscripts\GE_Wing_To_Wing_Report.xlsx"
oXls.Workbooks.open strPathExcel1
Set objSheet1 = oXls.ActiveWorkbook.Worksheets(1)
Set objSheet2 = oXls.ActiveWorkbook.Worksheets(2)
TotalRows=oXls.Application.WorksheetFunction.CountA(objSheet1.Columns(1)) - 3
TotalcolCopy=oXls.Application.WorksheetFunction.Match("Parent Business Process ID", objSheet1.Rows(3), 0)
objSheet1.Range(objSheet1.Cells(4,1),objSheet1.Cells(TotalRows,TotalcolCopy)).Copy(objSheet2.Range("A1"))
'=======================
oXls.ActiveWorkbook.SaveAs strPathExcel1
oXls.Workbooks.close
oXls.Application.Quit
'======================
样式-2
Option Explicit
Dim objSheet1,objSheet2,TotalRows,TotalcolCopy,strPathExcel1
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim oXls : Set oXls = CreateObject("Excel.Application")
Dim aData ': aData = oWb.Worksheets(1).Range("$A2:$C10")
Dim dicP : Set dicP = CreateObject("Scripting.Dictionary")
oXls.Workbooks.Open(oFs.GetAbsolutePathName("Test.xlsx"))
Set objSheet1 = oXls.ActiveWorkbook.Worksheets(1)
Set objSheet2 = oXls.ActiveWorkbook.Worksheets(2)
TotalRows=oXls.Application.WorksheetFunction.CountA(objSheet1.Columns(1)) - 3
TotalcolCopy=oXls.Application.WorksheetFunction.Match("Parent Business Process ID", objSheet1.Rows(3), 0)
objSheet1.Range(objSheet1.Cells(4,1),objSheet1.Cells(TotalRows,TotalcolCopy)).Copy(objSheet2.Range("A1"))
'=======================
oXls.ActiveWorkbook.SaveAs "Test.xlsx"
oXls.Workbooks.close
oXls.Application.Quit
'======================
你们能告诉我 Style-1 和 Style-2 有什么区别吗?因为在 Style-1 中,所有复制的数据都被保存了,而在 Style-2 中不是这样。这个设计问题主要是我从早上开始面临的整体问题。
Style-2 在哪些方面不完美?