VBA Code Help with Moving Rows

snaplink22

Board Regular
Joined
Jul 6, 2018
Messages
129
Hello,

I am attempting to move any of the rows in my first sheet to the second sheet when my drop down list changes from any other option to "Completed" in column A. Here is the code I have currently, but it's not working:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
On Error GoTo errhandler
If Target = "Completed" Then
Target.EntireRow.Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
Target.EntireRow.Delete
End If
Application.ScreenUpdating = True
errhandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

If possible, I would also like to have that same option pull that row back to Sheet1 if any of the drop down options other than "Completed" is changed.
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,037
Office Version
  1. 365
Platform
  1. Windows
You need to swap these two lines round
VBA Code:
Application.EnableEvents = False
 If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
You will also need to re-enable events before it will work.
 

snaplink22

Board Regular
Joined
Jul 6, 2018
Messages
129
You need to swap these two lines round
VBA Code:
Application.EnableEvents = False
If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
You will also need to re-enable events before it will work.

How do I re-enable events? New to VBA/Macros.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,037
Office Version
  1. 365
Platform
  1. Windows
Just run this
VBA Code:
sub Reset()
Application.EnableEvents = True
End Sub
 

snaplink22

Board Regular
Joined
Jul 6, 2018
Messages
129

ADVERTISEMENT

Just run this
VBA Code:
sub Reset()
Application.EnableEvents = True
End Sub

Err, how do I do that if I already have my previous code in there?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,037
Office Version
  1. 365
Platform
  1. Windows
Just put that sub in any module & run it. You should then be able to use your change event.
 

snaplink22

Board Regular
Joined
Jul 6, 2018
Messages
129

ADVERTISEMENT

Just put that sub in any module & run it. You should then be able to use your change event.

Sorry I'm uber new to VBA coding. Here's a screen shot of what I have. The Reset code you gave me is in Module 1. Not sure how I run it.

1590677418671.png
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,037
Office Version
  1. 365
Platform
  1. Windows
Just put the cursor in the code & hit F5
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,037
Office Version
  1. 365
Platform
  1. Windows
Because you have deleted the row, there is no way you can change Completed to anything else. :unsure:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,780
Messages
5,598,038
Members
414,205
Latest member
Tushark

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
Top