For Next structure query

shumba

Board Regular
Joined
Oct 5, 2010
Messages
168
Hi,


Peter kindly sent me the Sub Procedure below to use in my project. The procedure is designed to remove duplicated three letter codes in a list which is periodically updated into a list in column A.


Being a novice at VBA I am just trying to get my head around the For Next structure. I understand the r of the For r part is the counter variable. LR (last range I presume) To 9 Step-1. The 9 Step -1 part, does this mean that the procedure goes up one row at a time checking the next nine rows above?


Code:
Sub Check_for_previous_occurance_of_code()
      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
Thanks,


Rob.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
In the future you should stick to your original post so everyone can see how you got to where you are now. ;)
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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