Good Day,
I am trying to copy data from Sheet1 (which meets the conditions of an IF statement) and then paste the relevant cells for said row into Sheet2 of the same workbook.
Initially I managed to use the following code to simply pull in the relevant rows:
I then changed the code to try to copy specific cells to new columns in the destination worksheet:
The problem with the second code is that it simply overwrites the same line over and over - I need it to write to a new line.
The solution may be simple, but I am somewhat of a novice and I have exhausted all my abilities in trying to crack this enigma.
Any help would be greatly appreciated.
Kind Regards,
Khayyam
I am trying to copy data from Sheet1 (which meets the conditions of an IF statement) and then paste the relevant cells for said row into Sheet2 of the same workbook.
Initially I managed to use the following code to simply pull in the relevant rows:
Code:
Sub Copy_to_Sheet2()
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
If (Worksheets("Sheet1").Cells(i, 22).Value <> "Y" And Worksheets("Sheet1").Cells(i, 19).Value = "Yes") Then
Worksheets("Sheet1").Rows(i).Copy
Worksheets("Sheet2").Activate
b = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet2").Cells(b + 1, 1).Select
Worksheets("Sheet2").Cells(b + 1, 1).PasteSpecial xlPasteValues
Worksheets("Sheet1").Cells(i, 22).Value = "Y"
End If
Next
Application.CutCopyMode = False
End Sub
I then changed the code to try to copy specific cells to new columns in the destination worksheet:
Code:
Sub Copy_Arrivals_to_SiteVisits()
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Set sht1 = Sheets("Sheet1")
Set sht2 = Sheets("Sheet2")
a = sht1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
b = sht2.Cells(Rows.Count, 1).End(xlUp).Row
For i2 = 6 To b
If (sht1.Cells(i, 22).Value <> "Y" And sht1.Cells(i, 19).Value = "Yes") Then
sht2.Cells(i2, 7) = sht1.Cells(i, 3)
sht2.Cells(i2, 8) = sht1.Cells(i, 5)
sht2.Cells(i2, 9) = sht1.Cells(i, 4)
sht2.Cells(i2, 10) = sht1.Cells(i, 13)
sht2.Cells(i2, 14) = sht1.Cells(i, 7)
sht1.Cells(i, 22).Value = "Y"
Else
End If
Next i2
Next i
Application.CutCopyMode = False
End Sub
The problem with the second code is that it simply overwrites the same line over and over - I need it to write to a new line.
The solution may be simple, but I am somewhat of a novice and I have exhausted all my abilities in trying to crack this enigma.
Any help would be greatly appreciated.
Kind Regards,
Khayyam
Last edited by a moderator: