[英]Copy entire excel row and paste to the bottom of the table
I'm writing an Excel Macro that goes through an Excel table row by row and is supposed to copy an entire row and paste it under the last row when a condition is met. 我正在编写一个Excel宏,它逐行遍历Excel表,并且应该复制整行并在满足条件时将其粘贴到最后一行。 Looping through the rows and meeting the condition is all working but I'm stuck on copying an certain row and pasting it to the end of the table. 在行中循环并满足条件都可以正常工作但我仍然坚持复制某行并将其粘贴到表的末尾。
Sub Makro1()
Application.Goto Reference:="Makro1"
Dim i As Integer
With ActiveSheet
'for looping
totalRows = .Cells(.Rows.Count, "A").End(xlUp).Row
'index of last row even after rows have been added
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'data starts at row #3
For i = 3 To totalRows
If Cells(i, 19).Value > 0 Then
number = Cells(i, 19).Value
Do While number > 0
lastRow = lasRow + 1
Rows(lastRow) = Rows(i).Value
number = number - 1
Loop
End If
Next i
End With
End Sub
I get runtime error 1004. I know the nested loops are terrible, I simply need this for work (non-coding) to make my life easier. 我得到运行时错误1004.我知道嵌套循环很糟糕,我只需要这个工作(非编码)来让我的生活更轻松。
The error: 错误:
Run-time error '1004': 运行时错误'1004':
Application-defined or object-defined error 应用程序定义或对象定义的错误
... occurs on the first line of your code: ...发生在代码的第一行:
Application.Goto Reference:="Makro1"
That statement expects a named range with name "Makro1", but cannot find it. 该语句需要一个名为“Makro1”的命名区域,但找不到它。 If it would have found it, the range would have scrolled into view. 如果它找到它,范围将滚动到视图中。 If this is not important to you, then just comment that line out: 如果这对您不重要,那么只需注释掉该行:
' Application.Goto Reference:="Makro1"
Otherwise, open the "Names Manager" from the "Formulas" tab on the ribbon, and check the named ranges your Workbook has. 否则,从功能区上的“公式”选项卡中打开“名称管理器”,并检查工作簿具有的命名范围。 Possibly recreate "Makro1" if you know which range was supposed to be called that way. 如果您知道应该以这种方式调用哪个范围,可能会重新创建“Makro1”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.