1

我一直在桌子上敲我的头,试图破坏我的大脑以获得答案,但在我看来,我的大脑只是不想工作。我已经走到了这一步,但似乎没有更进一步......

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

如主题中所述,此脚本的要点是三个方面。

  1. 从工作表中获取字段,将它们粘贴到一行中。
  2. 将行删除,并将其粘贴到同一工作簿中的另一张工作表中。
  3. 从单元格 Z1 的第二张表复制到刚插入的行的开头。

第三部分我还没有完成,如果有人可以帮助我,将不胜感激。

4

1 回答 1

1

这是你正在尝试的吗?

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
于 2012-04-24T15:32:35.207 回答