![使用宏将数据从一个工作表的一行复制到另一个工作表](https://linux22.com/image/1502217/%E4%BD%BF%E7%94%A8%E5%AE%8F%E5%B0%86%E6%95%B0%E6%8D%AE%E4%BB%8E%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E8%A1%A8%E7%9A%84%E4%B8%80%E8%A1%8C%E5%A4%8D%E5%88%B6%E5%88%B0%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%B7%A5%E4%BD%9C%E8%A1%A8.png)
我正在处理一个电子表格,需要将一个工作表上生成的信息复制到另一个电子表格中以供打印。主电子表格(数据表)上的信息是通过两个下拉列表生成的,其中包含对象的高度和宽度。我希望能够将数据表上生成的信息复制到打印表上,并通过将新的高度宽度组合复制到打印表上的新行来继续此过程。到目前为止,我拥有的宏给我一个错误,我想知道是否有解决此问题的方法
Sub copyRow()
Dim wsd1 As Worksheet
Dim wsd2 As Worksheet
Dim wsp As Worksheet
Dim Row1 As Long
' define which worksheet to work on, i.e. replace Sheet1 with the name of your sheet
Set wsd1 = ActiveWorkbook.Sheets("Data Sheet").Range("B11:H11")
Set wsd2 = ActiveWorkbook.Sheets("Data Sheet").Range("M11:R11")
Set wsp = ActiveWorkbook.Sheets("Print Sheet")
' determine the last row with content in column A and add one
Row1 = Worksheets("Print Sheet").Cells(Rows.Count, "C").End(xlUp).Row + 1
' copy data from data sheet to print sheet
wsd1.Copy wsp.Range("C" & Row1)
End Sub
谢谢你的帮助!
迈克尔
答案1
Dim wsd1 As Worksheet
[ ... ]
Set wsd1 = ActiveWorkbook.Sheets("Data Sheet").Range("B11:H11")
您正在尝试将 Range 分配给 Worksheet 对象。
Dim wsd1 As Range
[ ... ]
Set wsd1 = ActiveWorkbook.Sheets("Data Sheet").Range("B11:H11")