SunQuest
 
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old July 25th, 2004, 09:24 PM
texaport texaport is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 texaport User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VBA in Excel- Split 1st & last names from same cell

I have a column containing "Last_Name, First_Name" that needs to be split into two columns, "Last_Name" & "First_Name". Last is separated from first by a comma and a space. Of course, names are of varying length so I can't specifty string length. I'm no programmer by any means, but I can open a macro in the VB editor and make changes as recommended without going into seizures. Any thoughts on how I can make this happen? And since I'll likely need to do it in the future, how can I combine the Last and First names from separate cells into a single cell and separate them with a comma and space? If you only have time to answer one question, the first is the most pressing.
Thanks.

Reply With Quote
  #2  
Old July 27th, 2004, 01:07 AM
texaport texaport is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 texaport User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Bump...additional info

I tried creating a macro as follows:
Starting with first cell- "F2" to select active cell, "Ctrl+left" arrow to get to beginning of First_Name, "Backspace Backspace" to erase space and comma, "Shift+End" to select First_Name, "Ctrl=X" cut, "Tab" to index to adjoining cell, "Ctrl+V" paste, "Down Arrow", "Left Arrow" to start over at next combined cell. Macro only runs in the cells I recorded it in. Seems it relates to relative values, but again, I don't know enough to proceed. Any suggestions or leads are greatly appreciated.

Reply With Quote
  #3  
Old July 27th, 2004, 12:05 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
You're going to need to write a macro that can tell where your comma is in the string.
Code:
    Dim firstName As String
    Dim lastName As String
    Dim n As Integer
    Dim rowNum As Integer
    Dim colNum As Integer
    rowNum = 1
    colNum = 1
    
    While Cells(rowNum, colNum).Value <> ""
        n = InStr(1, Cells(rowNum, colNum).Value, ",")
        lastName = Left(Cells(rowNum, colNum).Value, n - 1)
        firstName = Right(Cells(rowNum, colNum).Value, Len(Cells(rowNum, colNum).Value) - n - 1)
        Cells(rowNum, colNum + 1).Value = firstName
        Cells(rowNum, colNum + 2).Value = lastName
        rowNum = rowNum + 1
    Wend

This is the basic code that is needed for what you are asking for it to do. Now depending on where you want the first and last names to go and what column is holding the names, will mean that you will need to change the cell references (I'm using 1 because I had my names start in A1 and then go to A2 ect.)
To change it from two cells to one, you'll more or less want to do the same thing, but in reverse, take the two cells and concatenate the values:
Code:
cells(1, 3).value = cells(1, 2).value & ", " & cells(1, 1).value

Once again, this is assuming that you're first and last names are in cells A1 and B1 respectively. I hope this helps and if you should have any further questions, please feel free to ask.

Reply With Quote
  #4  
Old July 28th, 2004, 01:06 AM
texaport texaport is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 3 texaport User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You rock!!! Thanks a bunch. It worked perfect. Only thing that needed to be changed was the first row reference. Fortunately, I got some help from a local programming whiz that spotted my error. Otherwise, perfect. Thanks for the reply. I'll be visiting again with more questions as they arise, and hopefully maybe offer a little help as I learn more. Great forum too.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VBA in Excel- Split 1st & last names from same cell


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway