Changing value of cell after copy is complete.

Ryan_s

New Member
Joined
Jan 16, 2025
Messages
5
Office Version
  1. 2013
Platform
  1. Windows
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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
One other thing, I noticed when I execute the copy command the criteria cell has a moving green dotted border around it. Is there a way so it doesn't have this border?
1737084338081.png
 
Upvote 0
Untested here :

VBA Code:
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, 1).Value = "Assigned"
        
        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
 
Upvote 0
Untested here :

VBA Code:
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, 1).Value = "Assigned"
       
        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
Thanks, almost worked. It didn't change the source cell (Log Assignment) but did change the first column in the "Stocks" worksheet to assigned.
 
Upvote 0
Change:
VBA Code:
Worksheets("Options Sell").Cells(i, 1).Value = "Assigned"

To:
Code:
Worksheets("Options Sell").Cells(i, 17).Value = "Assigned"
 
Upvote 0
Try pasting the following just above the "End Sub" line :

VBA Code:
Application.CutCopyMode = False
 
Upvote 0
Solution

Forum statistics

Threads
1,225,626
Messages
6,186,092
Members
453,337
Latest member
fiaz ahmad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top