2013-06-04 4 views
0

원하는 결과를 얻는데 약간의 어려움이 있습니다. 예 현재 결과 = 시트의 최종 값 (입력) 쉬트 = 마지막 2 행 값 (입력) 다음 시트 (시트 1)의 전체에 열이 바로 반영 Excel VBA : 셀을 반복하고 값을 다른 워크 시트로 복사

원하는 결과 베드로

"베드로"입니다 (: B12 B9) "베드로가"

일부를 제공 할 수 있습니다 여기 너희들 희망 "데이비드"와 범위를 반영 : (B8 B5) "데이비드는"다음 "베드로는"내가 (Sheet1의) 시트에서 달성 희망하는 범위 이 문제에 대한 조언. 사전에 감사합니다 :)))

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

나는 완전히 당신의 요구 사항을 이해하지만 어쩌면 이것은 당신이 필요 확실하지 :

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 
관련 문제