简体   繁体   English

使用宏将数据从Excel工作表复制到另一个工作表

[英]Copy data from excel sheet to another using macro

I have a sheet Rolling Plan in copy.xls worksheet.I want to copy it to Book1.xls worksheet in Sheet NO1 in Range A1:H6 我在copy.xls工作表中有一个工作表滚动计划,我想将其复制到范围A1:H6的NO1工作表中的Book1.xls工作表中

The macro in Book.xls Book.xls中的宏

  Sub CopytoPS()
   Dim sfil As String
   Dim owbk As Workbook
   Dim sPath As String

   sPath = "C:\Users\Nirmala\Desktop\website" 'Change the file path for your purposes
   sfil = Dir(sPath & "copy.xls")

   Range("B6:H6").Copy
   Set owbk = Workbooks.Open(sPath & sfil)
   owbk.Sheets("RollinPlan").Range("B6:H6").End(xlUp).Offset(1, 0).
   PasteSpecial  xlPasteValues
    owbk.Close True 'Save opened workbook and close
    sfil = Dir

End Sub 结束子

This does the following: 这将执行以下操作:

1) Open copy.xls and copy data in range B6:H6 1)打开copy.xls并复制范围B6:H6

2) Pastes the data into workbook Book1 in range A1:H6 on sheet NO1 2)将数据粘贴到表NO1A1:H6范围的工作簿Book1

Sub CopyData()
    Dim filePath As String, wb As Workbook

    filePath = "C:\Users\Nirmala\Desktop\website" 'Change the file path for your purposes
    Set wb = Workbooks.Open(Filename:=filePath & "\" & "copy.xls")

    wb.Worksheets("Rolling Plan").Range("B6:H6").Copy Destination:=ThisWorkbook.Worksheets("NO1").Range("A1:H6")
    wb.Close
End Sub

Note that I am not quite sure why the data range you are copying to (ie A1:H6 ) is much larger than the actual copied range (ie B6:H6 ). 请注意,我不太确定为什么要复制到的数据范围(即A1:H6 )比实际复制的范围(即B6:H6 )大得多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用宏将数据从一张纸复制到Excel 2007中的另一张纸? - How can I copy data from one sheet to another sheet in Excel 2007 using a macro? 如何仅从一个Excel工作表复制公式,该工作表可以使用宏动态增长到另一工作表 - How to copy only formulas from one excel sheet which can dynamically grow to another sheet using macro Excel宏复制单元格范围并将数据粘贴到另一个工作表 - Excel Macro Copy cell range & paste data one sheet to another Excel 使用 VBA 将单元格数据从一张纸复制到另一张纸 - Excel Copy Cell Data from one sheet to another using VBA Excel宏-将数据从一张纸传输到另一张纸时发送自动电子邮件(复制整行) - Excel macro - sending automatic email when transferring data from one sheet to another (copy full row) Excel宏可根据特定的匹配条件将数据从一张纸复制到另一张纸 - Excel macro to copy data from one sheet to another based on specific matching conditions Excel宏-迭代地将行从一张纸复制到另一张纸 - Excel macro - Iteratively copy rows from one sheet to another Excel 将内容从一张纸复制到另一张纸,无需 VBA/宏 - Excel copy contents from one sheet to another without VBA/Macro Excel宏可将范围从一张纸复制到另一张纸 - Excel macro to copy range from one sheet to another 使用excel VBA将数据从一张纸复制并粘贴到另一张纸,然后从第二张纸复制到第三张纸 - Copy and paste data from one a sheet to another sheet, and from second sheet to third using excel VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM