1st name and 2nd name mixed up

Katyusa82

New Member
Joined
Jul 27, 2017
Messages
5


Hi,<o:p></o:p>


I have a problem to which I can't find
answer anywhere. I have a long list of costs with employee names. The problem
is that the names in the list are not consistently written. Sometimes the 1st
name comes first, sometimes the 2nd. E.g. it can be John Doe or Doe John. I
have nearly 40,000 lines with more than 1,500 employees. As a
result, when I insert a pivot table I have two records for the same
person, therefore my results are not correct.<o:p></o:p>



Can someone advise me a solution?<o:p></o:p>


Thank
you.<o:p></o:p>



 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to the forum.

Please take a minute to read the forum rules, especially regarding cross-posting, and update this thread with the relevant links to your other posts. Thanks. :)
 
Upvote 0
Wow... Thanks for the constructive answer MickG...

I can neither edit nor delete the post. If any admins could delete it and also my registration, would be great.

Thanks.
 
Upvote 0
I imagine he meant that he was rethinking whatever his original suggestion was.

We don't delete accounts and it would seem a little premature to be deleting this thread, though it would be nice if you complied with the rules (which are the same in almost all forums, by the way).
 
Upvote 0
I'm sorry if you got the wrong end of the Stick, I was RETHINKing the code.
Try this for data starting "B4"

Code:
[COLOR="Navy"]Sub[/COLOR] MG27Jul54
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, nName [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Sp [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B4"), Range("B" & 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
    Sp = Split(Dn.Value, " ")
      nName = Sp(1) & " " & Sp(0)
       [COLOR="Navy"]If[/COLOR] Not .exists(Dn.Value) And .exists(nName) [COLOR="Navy"]Then[/COLOR] Dn.Value = nName
        .Item(Dn.Value) = Empty
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you Mick very much. Works perfectly.
As my table is quite big, there are some empty lines and then it gives me an error message. Do you have an idea how to solve it?
Thank you.
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG27Jul52
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, nName [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Sp [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B4"), Range("B" & 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 IsEmpty(Dn.Value) [COLOR="Navy"]Then[/COLOR]
    Sp = Split(Dn.Value, " ")
      nName = Sp(1) & " " & Sp(0)
       [COLOR="Navy"]If[/COLOR] Not .exists(Dn.Value) And .exists(nName) [COLOR="Navy"]Then[/COLOR] Dn.Value = nName
        .Item(Dn.Value) = Empty
  [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top