Share via

Mark second occurrence using Excel VBA macro

Anonymous
2013-08-09T23:56:40+00:00

Hi!  Warning - I'm an Excel VBA novice! 

I would like to create a column which marks duplicate entries in another column, and I would like only the second occurrence marked. Example:  Column B has entries (in rows 1-7): A,B,C,C,D,E,D.  I want a mark in another column which marks rows 4 and 7 as being duplicates of earlier rows.  How do I do this?

Using =COUNTIF($B$2:$B2, B2) >1 will mark TRUE for the second occurrence of any record with no problem.  However, I don't want to drag that formula down more than 1,000 rows!  The very simple macro I created marks "True" for each duplicate whereas what I would like would be True for only each second occurrence of data.  This is what I was using for a smaller test data set.  By the way, I'm using Mac Excel 2011.

Dim Row As Integer

For Row = 2 To 4

    Cells(Row, "A") = WorksheetFunction.CountIf(Range("B2:B13"), Cells(Row, "B")) > 1

Next Row

Thanks in advance for your help and advice.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-08-10T13:18:01+00:00

Try this:

.

.

For Row = 2 To 7

    Cells(Row, "A") = WorksheetFunction.CountIf(Range("B1:B" & Row), Cells(Row, "B")) > 1

Next Row

.

.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-08-10T15:27:04+00:00

    Absolutely Fabulous!   Many, Many THANKS!!

    Juliana

    Was this answer helpful?

    0 comments No comments