VBA for Moving Rows - Debugging Help Needed

Smilechild793

New Member
Joined
Apr 27, 2017
Messages
20
I'm trying to move the rows from my sheet labeled "Changes" to my sheet labeled "Print", when there is a "NO" written in column V of the "Changes" sheet. I have the below, but I keep getting an error when I run.

2n9kh1j.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  12/29/2018  3:21:38 AM  EST
If Target.Column = 22 Then
Dim ans As Long
Dim Lastrow As Long
Lastrow = Sheets("Print").Cells(Rows.Count, "V").End(xlUp).Row + 1
ans = Target.Row
If Target.Value = "NO" Then Rows(ans).Copy Sheets("Print").Rows(Lastrow)
Rows(ans).Delete
End If
End Sub
 
Upvote 0
So for the script to run you must enter "NO" into any cell in column V

Your script said If target.column = 22 which is column V
 
Upvote 0
What do you mean when you Hit Run

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

You enter NO in column V and the script runs.

There is no pressing of a button.
 
Upvote 0
For reference, the reason you were getting an error on the highlighted line is because of
Code:
End(X1Up)
you have a 1 (one) which should be an l (lowercase L)
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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