Move row then delete blank

Status
Not open for further replies.

dantheram

Board Regular
Joined
Aug 27, 2010
Messages
192
Office Version
  1. 365
Platform
  1. Windows
Hi all,

could someone help me mod this to delete each blank row after it has moved the data to another sheet. Currently, it works when there is only one "Y" marked row but, if there are multiple rows, it does not delete any of the blank rows.

Code:
Sub Move_Closed()Dim Check As Range, rng As Range, r As Long, lastrow2 As Long, lastrow As Long
Application.ScreenUpdating = False
lastrow = Worksheets("Open").UsedRange.Rows.Count
lastrow2 = Worksheets("Completed").UsedRange.Rows.Count
If lastrow2 = 1 Then lastrow2 = 0
    For r = lastrow To 2 Step -1
        If Range("F" & r).Value = "Y" Then
            Rows(r).Cut Destination:=Worksheets("Completed").Range("A" & lastrow2 + 1)
            If rng Is Nothing Then Set rng = Rows(r) Else Set rng = Union(rng, Rows(r))
            lastrow2 = lastrow2 + 1
            Else:
        End If
    Next r
    If Not rng Is Nothing Then rng.Delete
Application.ScreenUpdating = True
End Sub

thanks in advance
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Status
Not open for further replies.

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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