'Copy Cell to another sheet in condition is met Loop

I need to loop through a column and if a conditions if met copy cell from one sheet to another.

I'm finding problems with the incremental.. In this case double the results.

Thank you in advance. KR

Sub copycell()

Dim iLastRow As Long
Dim i As Long
Dim erow As Long

erow = 1

iLastRow = Worksheets("Clientes").Cells(Rows.Count, "C").End(xlUp).Row
For i = 13 To iLastRow
    If Sheets("Clientes").Cells(i, 3) = "0" Then
        Worksheets("Ficheros").Range("B" & erow).End(xlUp).Offset(1) = Sheets("Clientes").Cells(i, 4)

        erow = erow + 1
    End If
Next i

End Sub


Solution 1:[1]

You can achieve your result with AutoFilter, but my answer is trying to resolve your code using the For loop.

Modified Code

Option Explicit

Sub copycell()

Dim iLastRow As Long
Dim i As Long
Dim erow As Long

' get first empty row in column B in "Ficheros" sheet
erow = Worksheets("Ficheros").Range("B" & Rows.Count).End(xlUp).Row + 1

With Worksheets("Clientes")
    iLastRow = .Cells(.Rows.Count, "C").End(xlUp).Row

    For i = 13 To iLastRow
        If .Cells(i, 3) = "0" Then
            Worksheets("Ficheros").Range("B" & erow) = .Cells(i, 4)

            erow = erow + 1
        End If
    Next i
End With

End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shai Rado