Hi Gerry,
Delighted to have helped out!
No problem re explaining the code - it works like this:
When "i" has a value of 1, then "sht.Range("J1").Offset(i, 0).Value" points to the first company in the list in column J, i.e. the very first "offender".
As the value of "i" is incremented by the "For" loop the code scans down through the 40 cells in the list. The test:
just ignores the cells which contain only a dash - i.e. the ones at the bottom of the list.
The variable "j" is used to keep track of the next blank cell in column A - i.e. the list of unique names, & this value is incremented each time a new name is placed in this list.
The only other bit is the one which involves "strNames". This variable starts life with a value equal to the name of the first "offender" in column J, and as the code progresses, other UNIQUE company names are concatenated with it. In our example, by the third iteration "strNames" will contain a concatenation of the full names of Glendinning, Cockburn & Scottish Water. On the fourth iteration the "Instr" function shows that Cockburn (the fourth name on the list) has already been concatenated with "strNames" & so this instance is a duplicate and the name is NOT added to the list in column A.
I think this covers everything, but if you've any further queries please feel free to ask.
Thanks for your feedback & for letting me get involved. This was technically interesting for me & it's nice to know that I've managed to help someone out at the same time.
Hope to hear from you with another "challenge" sometime!
All the best,
Greg
Bookmarks