Macro help for repeating rows

gman70403

New Member
Joined
Apr 6, 2013
Messages
7
Excel 2007
Spreadsheet has Columns A thru J and has 15,000 rows
I would like to create a macro that will perform the following simple task:
Starting with row #2
If cell G2= G3 cell then delete only all data from row 2
repeat till row 15,000
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub atest()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("G" & Rows.Count).End(xlUp).Row
For i = LR To 3 Step -1
    With Range("G" & i)
        If .Value = .Offset(-1).Value Then .Offset(-1).EntireRow.Delete
    End With
Next i
Application.ScreenUpdating = True
End Sub
 

gman70403

New Member
Joined
Apr 6, 2013
Messages
7
I would also like to add a rule that before a row is deleted to check if d2=d3; if it does, then go ahead and delete, if not, do not delete
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub atest()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("G" & Rows.Count).End(xlUp).Row
For i = LR To 3 Step -1
    With Range("G" & i)
        If .Value = .Offset(-1).Value And .Offset(, -3).Value = .Offset(-1, -3).Value Then .Offset(-1).EntireRow.Delete
    End With
Next i
Application.ScreenUpdating = True
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,675
Messages
5,838,713
Members
430,566
Latest member
ChanchalSingh

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