I need a macro that selects the same foreground objects

Do you know a macro that allows you to select all foreground objects on the same layer?
I need it when there are by mistake overlaps of the same objects repeated on the document, such as several rows of overlapping circles. With the macro I would select all the foreground ones and delete the others.