VBA Cut/paste based on cell value

jashotze

New Member
Joined
Apr 2, 2018
Messages
6
Hey All,
First time poster, as I am having a real crap time getting this code to work... I found a segment on one of these forums and need to amend it slightly... I need to detail the row that is copied and subsequently pasted.

I have tried every form of syntax I know how. Even paid 20 bucks an hour for an online Code Mentor and they could get it to work. I don't know if it needs to be just scrapped and started over or what. I have tried probably 30 different variations to accomplish this, even recorded the entire thing of searching, cutting and deleting. No Luck.

From the marginal amount I know this one seems to have some extra stuff (A1.Select) but when I remove it the I get object errors. But if the line to delete can be found I won't care haha.

This code works, it just doesn't delete.... Please help!!!!

Code:
[COLOR=#000000][FONT=Helvetica]Sub Completed_Rows()[/FONT][/COLOR]

[COLOR=#000000][FONT=Helvetica]'Unprotect a worksheet with a password[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]Sheets("Hi-Pri").Unprotect Password:="ov22gov"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]Sheets("Completed").Unprotect Password:="ov22gov"[/FONT][/COLOR]

[COLOR=#000000][FONT=Helvetica]Dim lr As Long, lr2 As Long, r As Long[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]lr = Sheets("Hi-Pri").Cells(Rows.Count, "A").End(xlUp).Row[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]lr2 = Sheets("Completed").Cells(Rows.Count, "A").End(xlUp).Row[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]For r = lr To 2 Step -1[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]   If Range("T" & r).Value = "Complete" Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]       Rows(r).Copy Destination:=Sheets("Completed").Range("A" & lr2 + 1)[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]       lr2 = Sheets("Completed").Cells(Rows.Count, "A").End(xlUp).Row[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]   End If[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]   Range("A1").Select[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]Next r[/FONT][/COLOR]

[COLOR=#000000][FONT=Helvetica]'Protect worksheet with a password[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]Sheets("Hi-Pri").Protect Password:="ov22gov"[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]'ActiveWorkbook.Save[/FONT][/COLOR]
[COLOR=#000000][FONT=Helvetica]Sheets("Completed").Protect Password:="ov22gov"[/FONT][/COLOR]
 
Last edited by a moderator:
It Worked!!! You're a lifesaver! I didn't even think of that. But I have had a few instances where for some reason it wasn't running and I had to use the immediate window to turn it back on so the macro would work.. Thanks again!!
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,896
Members
449,194
Latest member
JayEggleton

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