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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,884
Members
449,477
Latest member
panjongshing

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