在实现预期结果方面面临一些困难。 当前结果=例如,工作表(输入)中的最后一个值是“Peter” 然后,工作表中的整个列(sheet1)将只反映彼得
期望的结果=表格中的最后2行值(输入)是“david”然后“peter”我希望在表格(Sheet1)中实现的是反映“david”和Range的范围(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
答案 0 :(得分: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