2017-10-17 1 views
0

하나의 통합 문서에서 다른 통합 문서로 데이터를 복사하는 데 정말 이상한 문제가 발생했습니다. 코드 스 니펫 : 처음으로 충족되는 두 번째 경우 문에서 조건까지 예상대로VBA 중첩 for 루프, 단 하나의 루프 만 진행됨

For iRow = 7 To iMaxCheckRows 
    strPartNum = thisSheet.Cells(7, 1).Value 
    If strPartNum <> "" Then 
     For iSourceRow = 4 To iMaxRows 
      If sourceBook.Worksheets(1).Cells(iSourceRow, 2).Value = strPartNum Then 
       thisSheet.Cells(iRow, 4).Value = sourceBook.Worksheets(1).Cells(iSourceRow, 4).Value 'here it gets stuck 
       Exit For 
      End If 
     Next iSourceRow 
    End If 
Next iRow 

모든 것이 작동합니다. 값은 올바르게 복사되지만 이후에는이 행에 고정됩니다. iRow가 증가하지만 iSourceRow가 아니며 iRow가 iMaxCheckRows에 도달 할 때까지 동일한 값이 복사됩니다. 단일 단계를 사용하여 디버깅을 시도했지만 iRow가 증가 된 동일한 줄에 그대로 있습니다.

전에 이런 종류의 행동을 본 적이 없습니다. 누군가 여기에 무슨 일이 일어나고 있는지 실마리가 있습니까?

+5

'strPartNum = thisSheet.Cells (7, 1) .Value'는'strPartNum = thisSheet.Cells (iRow, 1) .Value'가 아니어야합니까 ??? –

+0

'sourceBook'이란 무엇입니까? 어떻게 언급 되는가? 열렸습니까? – Vityata

+0

예, strPartNum = thisSheet.Cells (7, 1). 값은 실제로 strPartNum = thisSheet.Cells (iRow, 1)입니다. 값 - 감사합니다. – MarcMan

답변

0

strPartNum = thisSheet.Cells (7, 1) .Value은 참으로해야 strPartNum = thisSheet.Cells (iRow, 1) 속임수를 썼는지

.Value

. 이제 나는 어리 석다.