Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old September 21st, 2004, 11:24 AM
dameon01 dameon01 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Memphis, TN
Posts: 2 dameon01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to dameon01 Send a message via MSN to dameon01 Send a message via Yahoo to dameon01
Question Trying to Split First initial, middle initial, and Last name/Suffix with Excel Macro

Hi,

I am a Data analyst for a average-sized pharmaceutical company. I have been assigned the task of creating a macro the separates names. I could use Text to columns on the column of names that need to be separated, but I only need the space before the last name to be separated. So, in Column A would be the Full name(ex: J H williams III). In column B, the first an second initials would be located(ex: J H). The last name and suffix would be in the Column C. When I record a macro and use Text to Columns, I find that I can't specify for the macro to skip to the last name(basically the next word with 2 or more letters) and split there. Does anyone have a macro that can do this. Below is an example of how the data looks and how I need it to work.


K R Russell IV

The data needs to be split into columns on the same row

K R in Column B

&

Russell IV in column C


Any help would be appreciated.

Dameon

Reply With Quote
  #2  
Old October 4th, 2004, 05:12 PM
thecg thecg is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 thecg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Use Search instead

This is not in macro format (I rarely use macros), but you should get the idea anyway. Instead of using the Text function, use the Search function. This is similar to the Instr function in VB. The following formula could be placed in cell B1 to get the first two initials and no trailing space from cell A1 (the full name):

=LEFT(A1,SEARCH(" ",A1,3))

Then use the following formula in cell A3 to get the last name and suffix from A1:

=RIGHT(A1,LEN(A1)-SEARCH(" ",A1,3))

Like I said, it's not a macro, but hopefully it will help. It assumes you will always have the "A B Lastname suffix" format. If you have to separate names instead of initials, use the Search function again, but change it to look for the first space to capture the first name, and look for the second space less the length of the first name to find the middle name. The same syntax could be used to separate the last name.

Thanks,

thecg

Reply With Quote
  #3  
Old October 13th, 2004, 07:48 PM
JamesLe JamesLe is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Oakland, CA, USA
Posts: 131 JamesLe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m
Reputation Power: 4
RE: Excel Macro

Hello Dameon,

Paste the code below to your excel macro. Remember to change the workbook and worksheet to the suitable name for your case. Hope it will help.
'------------

Sub Macro1()

Dim MySheet As Worksheet
Dim RowNumber As Integer

Const ColumnA = 1
Const ColumnB = 2
Const ColumnC = 3
Set MySheet = Workbooks("Book1.xls").Worksheets("Sheet1")
With MySheet
RowNumber = 1
While Not IsEmpty(.Cells(RowNumber, ColumnA))
.Cells(RowNumber, ColumnB) = Left(.Cells(RowNumber, ColumnA), 3)
.Cells(RowNumber, ColumnC) = Mid(.Cells(RowNumber, ColumnA), 4)
RowNumber = RowNumber + 1
Wend
End With

'Application.Quit

End Sub
'------------
Attached Files
File Type: zip test.zip (9.0 KB, 288 views)

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Trying to Split First initial, middle initial, and Last name/Suffix with Excel Macro


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