Do Until loop query

shumba

Board Regular
Joined
Oct 5, 2010
Messages
168
Hi,


Column A has a list of three letter codes placed in each cell and is periodically updated.


The Sub Procedure below (kindly supplied by Michael) is designed to check the most recently added code against the codes already on the list. If the code is the same as any added before then it is deleted from the list.


Code:
Sub delem()
      Dim lr As Long, r As Long
      lr = Cells(Rows.Count, "A").End(xlUp).Row
      For r = lr - 1 To 9 Step -1
          If Range("A" & lr).Value = Range("A" & r).Value Then Rows(lr).Delete
      Next r
  End Sub
Please will someone show me the best way to loop this procedure up the list. At the moment it works well on the most recently added code. As there might be a number of duplicated codes added to the list at any one time I would like to be able to remove them as well. Being a novice at VBA I presume some sort off Do Until Loop would be the way to go.


Thanks,


Rob.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try

Code:
Sub delem()
Dim LR As Long, r As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR To 9 Step -1
    If WorksheetFunction.CountIf(Columns("A"), Range("A" & r).Value) > 1 Then Rows(r).Delete
Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,538
Messages
6,179,413
Members
452,912
Latest member
alicemil

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