Hi, I wrote this vba code tried to copy my data from Data Sheet to Target Sheet. With a condition, if a cell in column AC (Data Sheet) has value = 1 then cut entire row to the last row of Target Sheet. My code had an error that I couldn't figure it out. Could someone help me, please? Thank you.
Sub Copy_Data()
Dim Lrow As Long, LrowTarget As Long, c As Range
Application.EnableEvents = False
On Error Resume Next
Sheets("Data").Select
Lrow = Cells(Rows.Count, "AC").End(xlUp).Row
For Each c In Range("AC103:AC" & Lrow)
If c.Value = 1 Then
c.EntireRow.Cut
Sheets("Target").Select
LrowTarget = Cells(Rows.Count, "B").End(xlUp).Row
Cells(LrowTarget + 1, 1).Select
ActiveSheet.Paste
ElseIf c.Value = 0 Then
c.EntireRow.Hidden = False
End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub
Sub Copy_Data()
Dim Lrow As Long, LrowTarget As Long, c As Range
Application.EnableEvents = False
On Error Resume Next
Sheets("Data").Select
Lrow = Cells(Rows.Count, "AC").End(xlUp).Row
For Each c In Range("AC103:AC" & Lrow)
If c.Value = 1 Then
c.EntireRow.Cut
Sheets("Target").Select
LrowTarget = Cells(Rows.Count, "B").End(xlUp).Row
Cells(LrowTarget + 1, 1).Select
ActiveSheet.Paste
ElseIf c.Value = 0 Then
c.EntireRow.Hidden = False
End If
Next
On Error GoTo 0
Application.EnableEvents = True
End Sub