(Solved) – infinity loop issue VBA


pulls out sheet data. It keep goin to infinity loop. So what it does is that it would scan the target and then pulls out the data in which i need from the column and past it in the final. It would also check with the target data with the source data from the column.

Set source = ThisWorkbook.Sheets("list")
Set target = Sheets("Sheet")
Set final = ThisWorkbook.Sheets("Sales")    
'Set the column range where the data will be scanned through
Set targetCheck = target.Range("B:B")
'Define the last row
sourceLastRow = source.Range("I" & source.Rows.Count).End(xlUp).Row

'Start the For loop from first record to last row
For i = 2 To sourceLastRow

    sourceValue = source.Range("I" & i).Value
            With targetCheck
                Set targetFind = .Find(What:=sourceValue)
                'If zp code exist, copy entire row; Else endif
                If Not targetFind Is Nothing Then
                    'finalAddress is for checking if the row has already been copied
                    finalAddress = targetFind.address
                        'Set the row number that the data will be copied to
                        finalRow = Range("A" & Rows.Count).End(xlUp).Offset(1).Row
                        'Copy the data row
                        'Paste to the new sheet.
                        final.Range("A" & finalRow).PasteSpecial
                        'Find the next row with the zp code.
                        Set targetFind = .FindNext(targetFind)

                    Loop While Not targetFind Is Nothing And targetFind.address <> finalAddress
                End If
            End With
Next i
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *