• Status: Solved
• Priority: Medium
• Security: Public
• Views: 79

Excel 2010 macros/vba

I would to create two macros or vba code modules. That will check the records in a column and find duplicates.  The second macro would find a duplicate and increase the sequence number by 1 in the duplicate row.  I am including a sample spreadsheet below.  Tab "A" I would to find just the duplicates.  Tab "B" would find the duplicates and renumber the sequence number. The sequence number is in brackets.
mytest_macros.xlsx
0
centralmike
• 2
• 2
• 2
• +1
3 Solutions

System AnalystCommented:
You should have loop to scan each record one by one by also assigning relevant sequence number to duplicated record.
0

Author Commented:
How would you do that? Do have a sample on how to accomplish this task?
0

Change and Transition ManagerCommented:

you could just sort the records and then add a column (say B)
put formula =if(a2=a1;b1+1;0) in cell B2 and copy down

that will give you the number/occurrence (starting at zero). than add a column C where you put the formula:
=REPLACE(A2;FIND("[";A2);3;"[" & B2 & "]")

no coding needed

For A, I have no clue what you are trying to achieve
0

EngineerCommented:
For the part 2 you can use this macro

Sub numberdups()
Dim cel As Range
Dim n As Long
Dim i As Long
For i = Range("A2").End(xlDown).Row To 2 Step -1
Set cel = Range("A" & i)
n = WorksheetFunction.CountIf(Range("A1", cel.Offset(-1)), cel.Value)
cel.Value = Replace(cel.Value, "[0]", "[" & n & "]")
Next i
End Sub

For the first part how do you want to display the duplicates? Color them?
0

Author Commented:
MACRO WORKED GREAT
0

EngineerCommented:
What do you want to do with the first part?
0

System AnalystCommented:
Author said the codes were working fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.