Rename Duplicate Cells

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
528
Is it possible to have a macro compare the contents in column "C" and were it finds a duplicate entry the macro would add to the first entry "-Free".

For example

CB1270 - Free
CB1270

In the above example the macro would add the "-Free" to CB1270.

The duplicate entries are next to each other.

Thank you
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,534
do you really need a macro ? the following formulae puts free in the adjacent column :=-

=IF(COUNTIF($D$4:D4,D4)=1,"free","")

thanks

Kaps
 

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
528
The reason for wanting a macro to do this is the sheet in question is a download from the host system and the formulas would be deleted each time the report was downloaded.

Thank you
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Hi, Try:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG10Aug00
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("c1"), Range("c" & Rows.count).End(xlUp))

[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
            [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
                .Add Dn.Value, Dn.address
            [COLOR="Navy"]Else[/COLOR]
                Range(.Item(Dn.Value)) = Range(.Item(Dn.Value)) & "- Free"
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
528

ADVERTISEMENT

That worked

Thank you very much
 

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
528
One last question instead of changing the first duplicate item can the macro change the second item.

Thank you
 

Mldeuser

Well-known Member
Joined
Dec 27, 2008
Messages
528

ADVERTISEMENT

Any thoughts
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Hi, This code should change the second Duplicate, where ever it is, and even if there are more than 2 duplicates.
Code:
[COLOR="Navy"]Sub[/COLOR] MG11Aug40
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("c1"), Range("c" & Rows.count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
            [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
                .Add Dn.Value, 0
            [COLOR="Navy"]Else[/COLOR]
               [COLOR="Navy"]If[/COLOR] .Item(Dn.Value) = 0 [COLOR="Navy"]Then[/COLOR]
                    .Item(Dn.Value) = .Item(Dn.Value) + 1
                     Dn.Value = Dn.Value & " -Free"
               [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 

ELNERO

New Member
Joined
Jun 15, 2019
Messages
2
Hello,

I now this thread is kind of old but is it possible to modify this such that it effectively counts upwards. Basically so that for first instance I can add ".01" for second instance I can add ".02" and so on?

Thanks,
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,904
Messages
5,514,063
Members
408,982
Latest member
starryeyed223

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top