Pregunta

This shouldn't be complicated code, but I am new to Excel VBA. I've tried many different methods resulting in bugs, infinite loops, and wrong selections.

I need to go row by row through "Sheet1" selecting one row at a time, check if the value in Column J is correct (value = 131125), if it is then copy - paste the row to "Sheet2" (into the same row as it was in Sheet1).

Help is much appreciated! :)

¿Fue útil?

Solución

Sub Test()
For Each Cell In Sheets(1).Range("J:J")
    If Cell.Value = "131125" Then
        matchRow = Cell.Row
        Rows(matchRow & ":" & matchRow).Select
        Selection.Copy

        Sheets("Sheet2").Select
        ActiveSheet.Rows(matchRow).Select
        ActiveSheet.Paste
        Sheets("Sheet1").Select
    End If
Next
End Sub
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top