简体   繁体   English

复制整个Excel行并粘贴到表格底部

[英]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.

相关问题 复制并粘贴整行 - Copy and Paste Entire Row Excel VBA将整个数组从数组数组粘贴到表中 - Excel VBA Paste entire row from array of arrays into table Excel VBA复制并粘贴整个范围与条件? - Excel vba copy and paste the entire range with criteria? 搜索匹配,复制整行,粘贴到对应的 - Search for a match, copy entire row, and paste to corresponding Excel VBA 自动根据单元格值复制整行“X”次并粘贴到单独的工作表中 - Excel VBA automation copy entire row “X” times based on cell value and paste in separate sheet Excel宏:如果列B具有“ X”,则复制整行并粘贴到名为“列B”的工作表中 - Macro for Excel: If Column B has “X”, then copy entire row and paste in Worksheet named “Column B” Excel VBA 可根据文本将整行从 1 个工作表复制并粘贴到同一工作簿中的另一个工作表 - Excel VBA to copy and paste an entire row from 1 worksheet to another in the same workbook based on a text 如果单元格在Excel中为红色/绿色/黄色,则复制并粘贴整行 - Copy paste entire row if the cell has red/green/Yellow color in excel 如果表格范围内的单元格值等于“新建”,则复制整行并粘贴为工作表 1 中下一个空单元格中的值 - If cell value in table range equals “New” copy entire row and paste as values in sheet 1 in the next empty cell 查找具有列最大值的单元格,复制整个行并粘贴到第2行 - Find cell with max value of column, copy entire row and paste in row 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM