2013-06-28 2 views
0

Excel의 VBA에 매크로를 작성하여 목록의 각 데이터 행에서 특정 열의 값을보고 해당 값이 "예"이면 동일한 행의 다른 시트에 전체 행을 복사하고 붙여 넣습니다. 두 장의 이름을 "데이터"와 "최종"으로 지정합시다. 시트를 참조하여 코드를 실행할 때 열어 본 시트가 문제가되지 않도록해야합니다. Do 루프를 사용하여 더 이상 항목이없고 값을 확인하는 if 문이 발견 될 때까지 한 데이터 시트의 행을 순환합니다.VBA 코드가 포함 된 통합 문서의 시트간에 복사하여 붙여 넣기

한 시트에서 다른 시트로 전환하는 방법에 대해 혼란스러워합니다.

어떻게 다른 시트의 셀을 구체적으로 참조합니까? 여기

내가 생각했던 의사 코드입니다 :

Do while DataCells(x,1).Value <> " " 
    for each DataCells(x,1).Value="NO" 
     if DataCells(x,2).Value > DataCells(x,3).Value or _ 
     DataCells(x,4).Value < DataCells(x,5).Value 
      'Copy and paste/insert row x from Data to Final sheet adding a new 
      'row for each qualifying row 
     else 
      x=x+1 
     end 
    else if DataCells(x,1).Value="YES" 
Loop 
'copy and paste entire row to a third sheet 
'continue this cycle until all rows in the data sheet are examined 
당신은 더 명확하게 코드를 포맷해야
+0

; 지금 당장은 선이나 들여 쓰기가 없어 코드를 읽을 수 없습니다. – LittleBobbyTables

+0

검색 기능을 사용하십시오. – user2140261

답변

0
Sub FilterAndCopy() 

Application.ScreenUpdating = False 
Application.EnableEvents = False 
Application.Calculation = xlCalculationManual 

Dim sh As Worksheet, sh2 As Worksheet 
Dim lastrow1 As Long 
Dim lastcolumn1 As Long 



Set sh = ThisWorkbook.Sheets("Data") 
Set sh2 = ThisWorkbook.Sheets("Final") 

lastrow1 = sh.Cells(Rows.Count, "A").End(xlUp).Row ' Replace "A" With column that has the most Rows 
lastcolumn1 = sh.Cells(1, Columns.Count).End(xlToLeft).Column 

With sh.Range(.Cells(1, 1), .Cells(lastrow1, lastcolumn1)) 

'Replace the number in the field section with your Columns number 
    .AutoFilter , _ 
     Field:=1, _ 
     Criteria1:="yes" 

    .Copy sh2.Range("A1") 

End With 

Application.ScreenUpdating = True 
Application.EnableEvents = True 
Application.Calculation = xlCalculationAutomatic 

End Sub