2012-11-09 5 views
0

각 행 (헤더 제외)은 단일 항목을 나타내고 각 열은 필드 (꽤 표준 항목)를 나타내는 워크 시트가 있습니다. 필드는 BB 열까지 올라갑니다.Excel VBA : 워크 시트 행의 특정 인접하지 않은 셀을 다른 워크 시트의 행으로 복사

특정 입력란 (특정 입력란의 특정 값과 일치하는 입력란)을 다른 시트로 복사하고 싶습니다. 그러나 원본 시트에있는 모든 필드는 원 시트에 인접하지 않은 약 10 개만 필요합니다.

따라서 각 (유효) 행에 대해, 나는 이런 식으로 뭔가를 할 것이다 :

for each origRow in origSheet.Rows 
    if strcomp(origRow.cells(idCellNumber).value, myId, vbTextCompare) = 0 then 
     copySheet.Row(copySheetRowNumber).value = origRow.Range(Cells(1), Cells(8), Cells(15), Cells(4)) 
     copySheetRowNumber++ 
    end if 
next 

물론이 코드가 유효하지 않습니다. 또한 시트에 삭제 될 기존 데이터가 포함되어 있기 때문에 항목을 전체적으로 복사 한 다음 관련이없는 열을 삭제할 수 없습니다. 누구든지 이것을 달성하기위한 가장 빠른 방법을 제안 할 수 있습니까?

+1

http://www.mrexcel.com/forum/excel-questions/292030-copy-cell-workbook-paste-another-workbooks-cell.html에 설명 된 문제는 필요합니다. –

+0

bonCodigo : 필요한 것이 Juri Ruut의 답변과 다른 경우 데이터 시트의 화면을 복사 할 수 있습니까? –

답변

2
Dim arrSourceCols, arrDestCols 
Dim x As Long 

arrSourceCols = Array(1, 3, 5, 7) 
arrDestCols = Array(2, 4, 8, 12) 

For Each origRow In origSheet.UsedRange.Rows 
    If StrComp(origRow.Cells(idCellNumber).Value, myId, vbTextCompare) = 0 Then 

     For x = LBound(arrSourceCols) To UBound(arrSourceCols) 
      copySheet.Cells(copySheetRowNumber, arrDestCols(x)).Value = _ 
            origRow.EntireRow.Cells(arrSourceCols(x)).Value 
     Next x 

     copySheetRowNumber = copySheetRowNumber + 1 
    End If 
Next 
관련 문제