0

在达到预期结果方面面临一些困难。当前结果 = 例如,工作表(输入)中的最后一个值是“彼得”,那么工作表(工作表 1)中的整个列将只反映彼得

期望的结果=工作表(输入)中的最后两行值是“大卫”然后是“彼得”我希望在工作表(工作表1)中实现的是范围(B5:B8)反映“大卫”和范围(B9:B12)“彼得"

希望在座的各位大侠能就这件事给点建议。提前致谢 :)))

Sub playmacro()
    Dim xxx As Long, yyy As Long
    ThisWorkbook.Sheets("Input").Range("A2").Activate
    Do While ActiveCell.Value <> ""
        DoEvents
        ActiveCell.Copy
        For xxx = 2 To 350 Step 4
            yyy = xxx + 3
            Worksheets("Sheet1").Activate '"select Sheet1"
            With ActiveSheet
                'copy the first active cell value from worksheet "input" and paste onto "sheet1" range("B2:B5") basically 1 cell value will occupy 4 rows in "sheet1"
                'then jump to the next empty row, return back to worksheet "input" copy the next row value and paste the data into range("B6:B9")
                'the loop will keep repeating until sheet "input" activecell value is blank
                .Range(Cells(xxx, 2), Cells(yyy, 2)).PasteSpecial xlPasteValues
            End With
        Next xxx
        ThisWorkbook.Sheets("Input").Select
        ActiveCell.Offset(1, 0).Activate
    Loop
    Application.ScreenUpdating = True
End Sub
4

1 回答 1

0

不确定我是否完全理解您的要求,但也许这就是您所需要的:

Sub PlayMacro()
    Dim lngLastRow as Long
    With Sheets("Input")
        lngLastRow = .Range(.Rows.Count, 1).End(xlUp).Row
        Sheets("Sheet1").Range("B5:B8").Value = .Range(lngLastRow-1,1).Value
        Sheets("Sheet1").Range("B9:B12").Value = .Range(lngLastRow,1).Value
    End With
End Sub
于 2013-06-04T12:44:20.460 回答