Don Selecting cells

M

m

Dear Don
Thank you for your prompt reply, unfortunately I couldn't
use your code but you still might be able to help.
What I am trying to do is write a macro which will delete and remove all
the rows between the first two matching numbers in a column including one
matching number, because all the data between matching numbers is repeat
data

Yours Mark
 
D

Don P

m,

Please keep your reply in the same thread.

Sub test()
Set rng = Selection
For r = rng.Rows.Count To 1 Step -1
V = rng.Cells(r, 1).Value
If rng.Cells(r, 1).Value = rng.Cells(r - 1, 1) Then
rng.Rows(r).EntireRow.Delete
End If
Next r
End Sub


Don Pistulka
 
D

Don P

Sorry about that. I did not know if you were still on-line.

Anyway, we Don's have to stick together.

Don Pistulka
 
D

Don P

m,

Excuse me for butting in again, but appears to me from the way you describe
the problem, deleting all duplicates would work:

Sub test2()
Set rng = Selection
For r = rng.Rows.Count To 1 Step -1
dcell = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns(1), dcell) > 1 Then
rng.Rows(r).EntireRow.Delete
End If
Next r
End Sub


Don Pistulka
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top