Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Split Sort cell values in Excel - either Macro or VBA

Posted on 2014-04-30
8
Medium Priority
?
632 Views
Last Modified: 2014-04-30
Hello All,

I have thousands of cells with the following name in this format in each cell:

(A)
surname, firstname

This is the general format and the first and surname is always separated by a comma.

Can I switch and actually separate these out so I have firstname in one cell and surname in another - something like this?

(B)             (C)
Firstname  Surname


It would be great to have either as a macro or vba script I can run?

Thanks in advance - GISVPN
0
Comment
Question by:gisvpn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40032548
Why don't you simply use Text to Columns? It will do what you want, no code necessary.
text to columns
HTH,
Dan
0
 
LVL 8

Accepted Solution

by:
Naresh Patel earned 2000 total points
ID: 40032582
You can achieve this by formula too. assuming your name is in cell A3 then formula in
B3for Name =MID(SUBSTITUTE(A3," ",""),FIND(",",SUBSTITUTE(A3," ",""),1)+1,100)


For Surname Formula in Cell C3=LEFT(SUBSTITUTE(A3," ",""),FIND(",",SUBSTITUTE(A3," ",""),1)-1)

Thanks
0
 
LVL 8

Expert Comment

by:Naresh Patel
ID: 40032607
Formula is amended so if you tried with older one then it may produce wrong output, so pls try amended one.

Thanks
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Closing Comment

by:gisvpn
ID: 40032610
Dan - thanks for the suggestion - worked a treat. I had no idea there was this feature in Excel.

itjockey - I tried the formula also but it did not seem to work as expected.
0
 

Author Comment

by:gisvpn
ID: 40032612
Oh sorry  itjockey - we pressed submit at the same time, thanks will try the updated one.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 40032632
Here is a macro

Sub lastto1st()
Range("A2:A" & Rows.Count).SpecialCells(xlCellTypeConstants).Offset(, 1).FormulaR1C1 = "=replace(rc[-1],1,find("","",rc[-1]),"""")"
Range("A2:A" & Rows.Count).SpecialCells(xlCellTypeConstants).Offset(, 2).FormulaR1C1 = "=replace(rc[-2],find("","",rc[-2]),9999,"""")"
Range("B2:C" & Rows.Count).Value = Range("B2:C" & Rows.Count).Value
End Sub
0
 
LVL 8

Expert Comment

by:Naresh Patel
ID: 40032734
itjockey - I tried the formula also but it did not seem to work as expected.
You tried mine? & it is not produce result as expected ?
then why you accept my solution :)
 
in my formulas i had limits the name to 100 character if there is more then 100 character for name then try this for name (Assuming text string in A3) Cell B3=MID(SUBSTITUTE(A3," ",""),FIND(",",SUBSTITUTE(A3," ",""),1)+1,LEN(A3))

and for Surname  Cell C3 =LEFT(SUBSTITUTE(A3," ",""),FIND(",",SUBSTITUTE(A3," ",""),1)-1)

or provide me sample file i do it on your behalf.
Thanks
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40032861
Yeah, the OP said my solution works and yours doesn't and then accepts your solution :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question