Need Edit Help: Macro is leaving blank row behind after moving row to another tab.

ERICinWV

New Member
Joined
Jan 28, 2016
Messages
2
Hello all,
I found a macro to move a row to another tab in same workbook based upon whether there was a particular value.
I edited the sheet names and then cell reference range to a column in my workbook.
The macro did move the correct rows to the second tab, however, it left behind blank rows where it had cut the data from.
Note: This was not a very quick running macro - don't know if it is how written or just my computer speed. Sheet had less than 500 rows.
After running, I had to filter by blanks and then delete rows to get them out of Current tab.
When the macro is run, I would like the macro to automatically delete the row from "Current" tab after moving row to "Gone..." tab.
I would imagine I just need to add a line, but I am very new to learning macros.
Any help would be appreciated.
In advance, thank you for your time and help!

Here is my current macro:

Sub Get_Rid_of_X()
Dim Check As Range, r As Long, lastrow2 As Long, lastrow As Long
Application.ScreenUpdating = False
lastrow = Worksheets("CURRENT").UsedRange.Rows.Count
lastrow2 = Worksheets("Gone or Not Needed").UsedRange.Rows.Count
If lastrow2 = 1 Then lastrow2 = 0
For r = lastrow To 2 Step -1
If Range("B" & r).Value = "X" Then
Rows(r).Cut Destination:=Worksheets("Gone or Not Needed").Range("A" & lastrow2 + 1)
lastrow2 = lastrow2 + 1
Else:
End If
Next r
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

Does this do what you want...

Code:
Sub Get_Rid_of_X()
    Dim Check As Range, r As Long, lastrow2 As Long, lastrow As Long
    Application.ScreenUpdating = False
    lastrow = Worksheets("CURRENT").UsedRange.Rows.Count
    lastrow2 = Worksheets("Gone or Not Needed").UsedRange.Rows.Count
    If lastrow2 = 1 Then lastrow2 = 0
    For r = lastrow To 2 Step -1
        If Range("B" & r).Value = "X" Then
            Rows(r).Cut Destination:=Worksheets("Gone or Not Needed").Range("A" & lastrow2 + 1)
            Rows(r).EntireRow.Delete
            lastrow2 = lastrow2 + 1
        Else:
        End If
    Next r
    Application.ScreenUpdating = True
End Sub


igold
 
Upvote 0
Great, glad I could help. Thanks for the feedback!

igold
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,185
Members
449,071
Latest member
cdnMech

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