Leaves blank rows after row with specific word moved to sheet 2

hsolanki

Board Regular
Joined
Jan 16, 2020
Messages
204
Office Version
  1. 2010
Platform
  1. Windows
Hi everybody

i have found this code from here and it works perfect however when it is cut it from Sheet 1 to Sheet 2 with specific word "Completed" it cut all the rows that contains "Completed" on column "AG" however it then leave the blanks rows on sheet1 is there any way that when it is moved to sheet 2 from sheet1 it will continue to look for next row with the specific word and will also continue to delete each blank rows.

VBA Code:
Option Explicit
Sub Test()

Dim sht1 As Worksheet, sht2 As Worksheet
Dim i As Long

Set sht1 = ThisWorkbook.Worksheets("Full")
Set sht2 = ThisWorkbook.Worksheets("Completed")

For i = 2 To sht1.Cells(sht1.Rows.Count, "AG").End(xlUp).Row
    If sht1.Range("AG" & i).Value = "Completed" Then
 sht1.Range("A" & i).EntireRow.Cut Destination:=sht2.Range("A" & sht2.Cells(sht2.Rows.Count, "AG").End(xlUp).Row + 1)
     
    End If
Next i

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about
VBA Code:
Sub Test()

Dim sht1 As Worksheet, sht2 As Worksheet
Dim i As Long
Dim Rng As Range

Set sht1 = ThisWorkbook.Worksheets("Full")
Set sht2 = ThisWorkbook.Worksheets("Completed")

For i = 2 To sht1.Cells(sht1.Rows.Count, "AG").End(xlUp).Row
   If sht1.Range("AG" & i).Value = "Completed" Then
      sht1.Range("A" & i).EntireRow.Copy Destination:=sht2.Range("A" & sht2.Cells(sht2.Rows.Count, "AG").End(xlUp).Row + 1)
      If Rng Is Nothing Then Set Rng = sht1.Rows(i) Else Set Rng = Union(Rng, sht1.Rows(i))
    End If
Next i
If Not Rng Is Nothing Then Rng.EntireRow.Delete
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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