Help with loop macro, find next

JoGee

New Member
Joined
Jun 25, 2015
Messages
4
Hi there,
I seem to need a little help with my loop. values and rows will change. I'm looking at values in column A, if the value is the same as the value below (A2 - A3) delete A2, if it is diferent then move to the cell below.

this is my code
Dim rCell as Range
Set Rngy = Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
For Each rCell In Rngy
If rCell.Value = rCell.Offset(1, 0).Value Then
rCell.EntireRow.Delete
ElseIf rCell.Value <> rCell.Offset(1, 0).Value Then
rCell.Offset(1, 0).Select

End If

Next

for some reason it only does the first line and then stops - what am I missing. :confused:

thanks in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
you cant move down the row , deleting rows as you go.
you must move up, then you can delete a row and not affect the count.

for rows = rows.count to 1 step -1
if value then delete row.
next
 
Upvote 0
Ranman,

thank you for your input, it completely slipped my mind to start at the bottom and now I'm completely upsidedown with my code. Any suggestions would help.

Sample sheet below

I need the most recend date (Column B) in each group (column A) so is it better to sort each goup with the date ascending or descending, starting at the bottom and deleting.

 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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