简体   繁体   English

将数据从工作表复制到单行,删除然后将行粘贴到另一工作表的最后一行

[英]Copying data from sheet to single row, delete then pasting row to last row on another sheet

I have been hitting my head on the desk attempting to wrack my brain in attempt to get the answer, but it seems to me that my brain just doesn't want to work. 我一直在打着桌子,试图破坏我的大脑以试图得到答案,但是在我看来,我的大脑只是不想工作。 I've gotten this far, but it seems no further... 我已经走了这么远,但似乎没有进一步...

Sub CopyValues()
    Dim i As Integer

    'Internal NCMR
    Dim wsInt As Worksheet
    Dim wsNDA As Worksheet

    'Copy Ranges
    Dim c As Variant

    'Paste Ranges
    Dim p As Range

    'Setting Sheet
    Set wsInt = Sheets("Internal NCMR")
    Set wsNDA = Sheets("NCMR Data")
    Set p = Range("B54:U54")

    With wsInt
        c = Array(.Range("B11"), .Range("B14"), .Range("B17"), .Range("B20"), .Range("B23"), .Range("Q11") _
                , .Range("Q14"), .Range("Q17"), .Range("Q20"), .Range("R25"), .Range("V23"), .Range("V25") _
                , .Range("V27"), .Range("B32"), .Range("B36"), .Range("B40"), .Range("B44"), .Range("D49") _
                , .Range("L49"), .Range("V49"))
    End With

    For i = LBound(c) To UBound(c)
        p(i + 1).Value = c(i).Value
    Next

    With wsNDA
        Worksheets("Internal NCMR").Rows("54").Copy
        Sheets("NCMR Data").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    End With
End Sub

The point of this script as explained in the topic is three fold. 如主题中所述,此脚本的要点有三点。

  1. Take fields from a sheet, paste them into a row. 从工作表中获取字段,并将其粘贴到行中。
  2. Take row delete it,and paste it into another sheet in same workbook. 行删除它,并将其粘贴到同一工作簿中的另一个工作表中。
  3. Copy from 2nd sheet from cell Z1 to beginning of row just inserted. 从单元格Z1的第二张纸复制到刚插入的行的开头。

The third part I haven't gotten to yet, if someone could help me with that it be greatly appreciated. 第三部分我还没有讲到,如果有人可以帮助我,将不胜感激。

IS this what you are trying? 这是您要尝试的吗?

Option Explicit

Sub CopyValues()
    Dim i As Integer

    'Internal NCMR
    Dim wsInt As Worksheet
    Dim wsNDA As Worksheet

    'Copy Ranges
    Dim c As Variant

    'Paste Ranges
    Dim p As Range

    'Setting Sheet
    Set wsInt = Sheets("Internal NCMR")
    Set wsNDA = Sheets("NCMR Data")
    Set p = wsInt.Range("B54:U54")

    With wsInt
        c = Array(.Range("B11"), .Range("B14"), .Range("B17"), .Range("B20"), .Range("B23"), .Range("Q11") _
                , .Range("Q14"), .Range("Q17"), .Range("Q20"), .Range("R25"), .Range("V23"), .Range("V25") _
                , .Range("V27"), .Range("B32"), .Range("B36"), .Range("B40"), .Range("B44"), .Range("D49") _
                , .Range("L49"), .Range("V49"))
    End With

    For i = LBound(c) To UBound(c)
        p(i + 1).Value = c(i).Value
    Next

    With wsNDA
        Dim Lastrow As Long

        Lastrow = .Range("B" & Rows.Count).End(xlUp).Row + 1

        wsInt.Rows("54").Copy

        With .Rows(Lastrow)
            .PasteSpecial Paste:=xlPasteFormats
            .PasteSpecial Paste:=xlPasteValues
            .Interior.Pattern = xlNone
        End With

        With .Range("A" & Lastrow)
            If Lastrow = 3 Then
                .Value = 1
            Else
                .Value = Val(wsNDA.Range("A" & Lastrow - 1).Value) + 1
            End If

            .NumberFormat = "0#######"
        End With
    End With
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从工作表1复制到工作表2并粘贴数据之前,需要在电子表格中找到最后一行 - Need to find the last row in a spreadsheet before copying and pasting data from Sheet 1 to Sheet 2 将工作表复制到另一个工作簿的工作表的最后一行 - Copying sheet to last row of a sheet from another workbook 将数据从一张纸复制到另一张纸的最后一行 - Copy data from one sheet to the last row of another sheet 将未打开的excel工作表中的excel数据复制并粘贴到目标excel工作表到最后一行 - Copy and Pasting excel data from unopened excel sheet to destination excel sheet to the last row 将excel行从一个工作表复制到另一个工作表 - Copying excel row from one sheet to another 将匹配的行复制到另一张工作表中 - Copying the matched row in another sheet 识别非活动工作表中的最后一行,并从活动工作表中复制最后1行中的数据 - Identifying last row in a inactive worksheet and copying data in last+1 row from active sheet 复制整行并将其粘贴到新工作表中的下一个空行 - Copying a entire row and pasting it into the next empty row in a new sheet 从一张粘贴复制到另一张而不使用剪贴板的情况下,始终需要粘贴到第一行空白。出现错误424 - Copying from one sheet pasting to another sheet without using the clipboard, always needs to paste in the first empty row.Getting error 424 宏基于另一个工作表删除工作表上的行 - Macro that Delete a Row on a Sheet based on another Sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM