从行

时间:2016-10-30 22:44:37

标签: excel-vba vba excel

我正在尝试从一个工作簿工作表复制所有列并粘贴到另一个工作簿工作表,但粘贴从第A8行开始的所有列

我已经将代码工作从一个工作簿表复制并粘贴到另一个工作簿表,我只是无法弄清楚要添加的代码来粘贴从A8行开始的列。

这是我到目前为止所做的:

Set Data = Workbooks.Open(ThisWorkbook.Path & "\Technical Audit.xlsm", UpdateLinks:=xlUpdateLinksAlways)
Worksheets("Raw Data").Select

Set SourceImageColumn = Workbooks("Audit Dashboard.xlsm").Worksheets("Raw Image Data").Columns("A:D")
Set TargetImageColumn = Workbooks("Technical Audit.xlsm").Worksheets("Images").Columns("A:D")

SourceImageColumn.Copy Destination:=TargetImageColumn

Data.Save

提前感谢您提供任何帮助

2 个答案:

答案 0 :(得分:1)

**更新了代码** 如果您打开两个工作簿,此方法将起作用。我无法弄清楚你是否有这个。

Sub macro3()
Dim iRow        As Long
Dim lastRow     As Long
Dim nextRow     As Long
Dim wksSource   As Worksheet
Dim wksTarget   As Worksheet

Set wksSource = Workbooks("Audit Dashboard.xlsm").Worksheets("Raw Image Data")
Set wksTarget = Workbooks("Technical Audit.xlsm").Worksheets("Images")

lastRow = wksSource.Range("A" & wksSource.Rows.Count).End(xlUp).Row

nextRow = 8

With wksSource
    For iRow = 1 To lastRow
        .Range(.Cells(iRow, 1), .Cells(iRow, 4)).Copy wksTarget.Cells(nextRow, 1)
        nextRow = nextRow + 1
    Next iRow
End With
End Sub

答案 1 :(得分:1)

Set wsCore = Workbooks("Audit Dashboard.xlsm").Worksheets("Raw Image Data")
Set wsData = Workbooks("Technical Audit.xlsm").Worksheets("Images")

With Intersect(wsCore.Columns("A:D"), wsCore.UsedRange)
    .Columns("A").Copy Destination:=wsData.Range("A8")
    .Columns("B").Copy Destination:=wsData.Range("B8")
    .Columns("C").Copy Destination:=wsData.Range("C8")
    .Columns("D").Copy Destination:=wsData.Range("D8")
End With

https://stackoverflow.com/a/29359212/1544886

的修改后的答案

将从wsCore列A:D复制,并从A8开始粘贴到wsData:D8