Hi guys,
What I am looking to do is copy data from one sheet to another, however I only want it to copy columns A and B based on the cell value of Column E in each row
So far I have the following code which is able to copy the data, but currently pastes it on every column on the worksheet and I can't see why. Apologies if it is something simple, I am relatively new to VBA.
What I am looking to do is copy data from one sheet to another, however I only want it to copy columns A and B based on the cell value of Column E in each row
So far I have the following code which is able to copy the data, but currently pastes it on every column on the worksheet and I can't see why. Apologies if it is something simple, I am relatively new to VBA.
Code:
Sub HoldCodeSeparation()
Dim Source As Worksheet
Dim Target As Worksheet
Set Source = ActiveWorkbook.Worksheets("Hold Codes")
Set Target = ActiveWorkbook.Worksheets("Extract")
j = 2 ' Start copying to row 1 in target sheet
For Each c In Source.Range("E1:E1000") ' Do 1000 rows
If CStr(c) = "22" Then
Source.Range(Cells(c.Row, 1), Cells(c.Row, 2)).Copy Target.Rows(j)
j = j + 1
End If
Next c
End Sub