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. 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.
The error:
Run-time error '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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.