宏:将具有多个数据的一行复制到另一个工作表中的多行中

时间:2013-10-14 09:41:25

标签: excel-vba excel-2010 vba excel

我正在使用Excel 2010,尝试创建一个包含3个colunms的宏:测试名称,预期结果和测试数据。 测试数据列有多行,每行有多个数据条目(30) 我想将sheet1中的30个条目复制到多个行中。

这是我的代码:

Sub Practice()

    Dim testName As String
    Dim expectedResult As String
    Dim testData As String

    'copying TEST NAME rows to Sheet2
    Range("A2").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    ' Merging TEST NAME colunm in Sheet2
    With Sheet2
        For counter = 1 To 90
            .Range("A2:A32").Merge
       Next
       testName = counter + 1
    End With

    'copying EXPECTED RESULT to Sheet2
    Range("B2").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("B2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    ' Merging EXPECTED RESULT colunm in Sheet2
    With Sheet2
        For counter = 1 To 90
            .Range("B2:B32").Merge
        Next
        testName = counter + 1
    End With

    ' Copying TEST DATA colunm in Sheet1
    For i = 1 To 30

        Range("C2").Select
        Selection.Copy
        Sheets("Sheet2").Select
        Range("C2:C32").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

         i = i + 30

    Next

End Sub

0 个答案:

没有答案