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
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,481
Messages
5,601,918
Members
414,482
Latest member
morkar

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