Hey everyone, first post and excel newbie. I created some VBA code to copy certain cells of a row to a different worksheet based on criteria. I'm trying to add to the code so that "Log Assignment" is changed to "Assigned" on the source worksheet so that that row is no longer is copied when the code is executed again.
This is the code I'm using. I tried adding different things at the end but was not able to change the criteria cell after the copy. Thanks
Private Sub CommandButton1_Click()
Dim lastrow As Long, erow As Long
lastrow = Worksheets("Options Sell").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Options Sell").Cells(i, 17).Value = "Log Assignment" Then
Worksheets("Options Sell").Cells(i, 1).Copy
erow = Worksheets("Stocks").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 1)
Worksheets("Options Sell").Cells(i, 5).Copy
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 3)
Worksheets("Options Sell").Cells(i, 6).Copy
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 2)
Worksheets("Options Sell").Cells(i, 17).Copy
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 12)
End If
Next i
End Sub
This is the code I'm using. I tried adding different things at the end but was not able to change the criteria cell after the copy. Thanks
Private Sub CommandButton1_Click()
Dim lastrow As Long, erow As Long
lastrow = Worksheets("Options Sell").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("Options Sell").Cells(i, 17).Value = "Log Assignment" Then
Worksheets("Options Sell").Cells(i, 1).Copy
erow = Worksheets("Stocks").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 1)
Worksheets("Options Sell").Cells(i, 5).Copy
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 3)
Worksheets("Options Sell").Cells(i, 6).Copy
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 2)
Worksheets("Options Sell").Cells(i, 17).Copy
Worksheets("Options Sell").Paste Destination:=Worksheets("Stocks").Cells(erow + 1, 12)
End If
Next i
End Sub