使用MACRO将数据从一个工作表中的行复制到另一个工作表


0

我正在开发一个电子表格,需要将在一个工作表上生成的信息复制到另一个电子表格以进行打印。主电子表格(数据表)上的信息通过两个包含对象高度和宽度的下拉列表生成。我希望能够将数据表上生成的此信息复制到打印页上,并通过将新的高宽组合复制到打印页上的新行来继续此过程。我到目前为止的宏给了我一个错误,我想知道是否有任何解决方案可以解决这个问题

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

谢谢你的帮助!

迈克尔


它给你的错误是什么?
Burgi 2016年

Answers:


0
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")
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.