vba 将数据复制到Excel中另一个工作表上的特定单元格范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19503388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:59:24  来源:igfitidea点击:

Copy data to a specific cell range on another worksheet in excel

excelvbaexcel-vba

提问by Steve

HI I have this code which works well to copy and append data to a separate worksheet however I want it to paste to a specific cell range in the destination sheet, how do I go about ammending it?

嗨,我有这段代码可以很好地将数据复制和附加到单独的工作表,但是我希望它粘贴到目标工作表中的特定单元格范围,我该如何修改它?

Sub SummurizeSheets()
    Dim ws As Worksheet

    Application.ScreenUpdating = False
    Sheets("Summary").Activate

    For Each ws In Worksheets
        If ws.Name <> "Summary" Then
            ws.Range("D2:D6, D8:D15").Copy
            Worksheets("Summary").Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
        End If
    Next ws
End Sub

采纳答案by David Zemens

Modify this line so that it refers to the desired Worksheet and cell(s) address:

修改此行,使其指向所需的工作表和单元格地址:

Worksheets("Summary").Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)

For example, this puts it on a worksheet named "Another Sheet Name" and in column F, instead of column C:

例如,这将它放在名为“另一个工作表名称”的工作表和 F 列中,而不是 C 列中:

Worksheets("Another Sheet Name").Cells(Rows.Count, 6).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)

Update: You are using a somewhat dynamic range already, in conjunction with the Offsetmethod. If you have trouble getting this to paste the values to the desired location, let me know what that location is and I can give more detailed answer.

更新:您已经在使用某种动态范围和Offset方法。如果您无法将值粘贴到所需位置,请告诉我该位置是什么,我可以提供更详细的答案。