1

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

这是我的代码:

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
4

0 回答 0