I have VBA code that loops through each selected cell in Excel. I noticed that in some cases the cell count of the selection was higher than expected. If for example I manually select cells A1:A2 and then CTRL-click cell A2 I was expecting the cell count of the selection to be 2. To test it I ran this code:
Dim target As Range
Set target = Application.Selection
MsgBox target.Cells.Count
...and the cell count was actually three. The selection in this case refers to cells A1:A2 and A2 again.
How can I take a range like this that overlaps with itself and convert it to a range that does not overlap? This is a simple example but actual ranges can be much larger and contain larger overlapping ranges. Thanks!