473,610 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splitting Text

48 New Member
Hi There,

I have written a little script that should splitt FirstName, Mr.Ms.Miss and LastName. However, the raw data I received with which I will have to use my VB script, is a bit more complicated, and I can't solve that challenge yet. I need some tips from experts. :-)

Expand|Select|Wrap|Line Numbers
  1. 'Uses the Excel VBA split function
  2. Sub MyExcelSplitCells()
  3. Dim TempArray As Variant
  4. Dim rwIndex, colIndex
  5. With Sheet3
  6.     For rwIndex = 1 To .UsedRange.Rows.Count
  7.     TempArray = mySplit(Trim(.Cells(rwIndex, 1).Text))
  8.     For colIndex = 2 To UBound(TempArray) + 2
  9.     .Cells(rwIndex, colIndex).Value = TempArray(colIndex - 2)
  10. Next
  11. Next
  12. End With
  13. End Sub
  14. Function mySplit(str As String) As Variant
  15.     ReDim myArray(0)
  16.     Dim counter As Integer
  17.         counter = 0
  18.             For x = 1 To Len(str)
  19.             Select Case Mid(str, x, 1)
  20.             Case ",", " " '".", "-"
  21.         If Len(myArray(counter)) > 0 Then
  22.             counter = counter + 1
  23.     ReDim Preserve myArray(counter)
  24. End If
  25.  
  26. Case Else
  27.     myArray(counter) = myArray(counter) + Mid(str, x, 1)
  28. End Select
  29.     Next
  30.     mySplit = myArray
  31. End Function
  32.  
the Raw Data looks like:
Expand|Select|Wrap|Line Numbers
  1. AShok Kumar, Mr. Pandi
  2. Aanei, Mr. Paul
  3. Aarthi, Mrs. Aravamudhan
  4. Abbott, Mr. Neil
  5. Abcouwer, Mr. Eric
  6. Abd Manaf, Mrs. Fazilah
  7. Abdul Aziz, Mr. Ahmed
  8. Abdulgapul, Mr. Al-Ameen B
  9. Abdullaeva, Miss Roziya
  10. Abhishek, Mr. Banchhor
  11. Abhishek, Mr. Roy
  12. Abisamra, Mr. Atef
  13. Able, Mr. Klaus
  14. Abraham, Mr. Lionel
  15. Achuth Rao, Mr. Subramania Rao
  16. Acosta, Mr. Ernesto F.
  17. Adefioye, Mr. William
  18. Adeline Jenitha, Ms. Wilfred
  19. Adeyemi, Mr. Peter Adekunle (Peter)
  20. Adkinson, Mr. Desmond John
  21. Ageev, Mr. Fedor Borisovitch (Fedor)
  22.  
Basically, I need the FirstName (with Middle Name) in one column, Title in another, and LastName also.

The Script I wrote works, as long as there aren't MiddleNames. Does anybody have a hint? I would highly appreciate it.

Regards,
Sep 4 '07 #1
11 1627
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Check This :

Expand|Select|Wrap|Line Numbers
  1.     Dim sSQL As String
  2.     sSQL = "AShok Kumar, Mr. Pandi"
  3.  
  4.     Dim tarr
  5.     Dim i As Integer
  6.     Dim FName As String
  7.     Dim LName As String
  8.     Dim Title As String
  9.     '
  10.     tarr = Split(sSQL, ",")
  11.     FName = tarr(0)
  12.     '
  13.     sSQL = Replace(sSQL, FName, "")
  14.     sSQL = Replace(sSQL, ",", "")
  15.     sSQL = Trim(sSQL)
  16.     '
  17.     tarr = Split(sSQL, " ")
  18.     '
  19.     Title = tarr(0)
  20.     LName = ""
  21.     For i = 1 To UBound(tarr)
  22.         LName = LName & " " & Trim(tarr(i))
  23.     Next
  24.     MsgBox Title & " " & FName & LName
  25.     '
  26.  
Regards
Veena
Sep 4 '07 #2
Killer42
8,435 Recognized Expert Expert
Question: Do you trust the data to always include a title? This will make a difference to the logic.
Sep 4 '07 #3
alive84
48 New Member
Question: Do you trust the data to always include a title? This will make a difference to the logic.
Thanks for the ideas so far.

To Killer42:

No, there are also some, who have a Doctor as Title.

To Veena:

Thanks, I will try to use your input, but I am not really getting it why you are using SQL?

Thanks for the inputs.

Regards,
Sep 4 '07 #4
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

It is sSQL >> String Variable. It was already declared, so did not change the variable name.
You have to replace it with your Text / String data.

Regards
Veena
Sep 4 '07 #5
alive84
48 New Member
hI,

IT IS sSQL >> String Variable... It was already declared , So did not change the variable name..
U have to replace it with ur Text / String data

REgards
Veena

sorry, but how do I implement that in my script. I am lost, I am not really a VB professional... :-)

thanks
Sep 4 '07 #6
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Just replace your MySplit function:

Expand|Select|Wrap|Line Numbers
  1. Function mySplit(sSQL As String) As Variant
  2.     Dim tarr
  3.     Dim i As Integer
  4.     Dim FName As String
  5.     Dim LName As String
  6.     Dim Title As String
  7.     Dim NewArr(0 to 2) As String
  8.     '
  9.     tarr = Split(sSQL, ",")
  10.     FName = tarr(0)
  11.     '
  12.     sSQL = Replace(sSQL, FName, "")
  13.     sSQL = Replace(sSQL, ",", "")
  14.     sSQL = Trim(sSQL)
  15.     '
  16.     tarr = Split(sSQL, " ")
  17.     '
  18.     Title = tarr(0)
  19.     LName = ""
  20.     For i = 1 To UBound(tarr)
  21.         LName = LName & " " & Trim(tarr(i))
  22.     Next
  23.     NewArr(0) = Title
  24.     NewArr(1) = FName
  25.     NewArr(2) = LName
  26.     mySplit = NewArr
  27. End Function
  28.  
  29.  
You have used "str" as a variable name. It is a Reserverd Word and should be avoided using it as a variable.

Regards
Veena
Sep 4 '07 #7
Killer42
8,435 Recognized Expert Expert
No, there are also some, who have a Doctor as Title.
My question was whether it ever has no title.
Sep 5 '07 #8
Killer42
8,435 Recognized Expert Expert
People, just a quick note as Moderator - please don't use TXT-style abbreviations such as "u" for "you" and "ur" for "your". The posting guidelines require "clear, concise English". I know English varies a lot, and that's to be expected. But don't deliberately mangle it.
Sep 5 '07 #9
SammyB
807 Recognized Expert Contributor
Hi There,
<snip>
Basically, I need the FirstName (with Middle Name) in one column, Title in another, and LastName also.

The Script I wrote works, as long as there aren't MiddleNames. Does anybody have a hint? I would highly appreciate it.

Regards,
Just use Chuck Pearson's formulas or code, http://www.cpearson.com/excel/FirstLast.htm
As a Microsoft MVP for Excel, his site has lots of genius! --Sam
Sep 5 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2062
by: somaBoy MX | last post by:
I'm building a site where I need to pull very large blocks from a database. I would like to make navigation a little more user friendly by splitting text in pages which can then be navigated. I know how to split a string in chunks, but I need to find a method to make sure the text isn't split in the middle of a word. Any ideas? Thanks,
3
3281
by: Sandman | last post by:
I am splitting a text block into paragraphs, to be able to add images and stuff like that to a specific paragraph in a content management system. Well, right now I'm splittin on two or more newlines, so this text block: Hello, my nickname is Sandman and I am coding some PHP Call me
3
2534
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I can envision unions of node sets, and unions of node text. But I know there's much more to the subject than that, if not more alternatives than greater technical detail. TIA,
1
1867
by: Andi B | last post by:
If I have an array set up like so to contain a small code, and the name of the person to whom the code relates, the values split by a comma: DMCName="1SC,Andrea Pidgeon" and I want to be able to return the name when someone enters the code into a text box, is there a way to split the array and only return the name? - Bearing in mind that there will be more than one code, and other details will be included besides the name of the...
1
1739
by: Andy Britcliffe | last post by:
Hi I'm faced with the situation where I could have a single physical file that could contain multiplie XML documents e.g file.txt contains the following: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE doc SYSTEM "1.0b.dtd"> <doc transmission-date="20050715T154340Z" >
2
1765
by: Jenny | last post by:
Hello All! I have a long XML file that I should transmit to other computer using http. Problem is that the whole XML Document is too large for one transmitting. What is the nicest way to split XML document into smaller pieces e.g. to 10 pieces? XML document is same kind what comes to itäs tags.
2
2868
by: Matt | last post by:
Hi, I'm ridiculously new to Access (about a week!) so please be patient! My database is a record of British Standards. Each has a unique identifier. Some are split into parts. I would like the user to be able to input the data into a single textbox using a form like this: Record1: BS 1490-1 Record2: BS 1490-2
7
4901
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
How do I split a title attribute value into lines within the source code so that the paragraph gets reassembled by the browser when it is being displayed? Microsoft Internet Explorer 7 preserves my line breaks and it is not what I want. The only workaround is to leave a long line in the source code. I thought a well behaved language should provide a way to fit reasonable code into 80 columns of width. Chris
2
3264
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to lines it worked quite well but srttok isnot working for multiple blank or commas. Can strtok do this kind of splitting if it cant what should i use . Unal
2
1342
by: David Jackson | last post by:
Hello, The company I'm working for has taken over a smaller company with a fairly large customer base. We want to send an email to that customer base informing them of the takeover but the mailing list is not held in a database. In fact we've been given it as a Word document. The individual email addresses are in the format: "Name <address>" e.g. Bill Gates <billg@microsoft.com>;
0
8148
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8097
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8238
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6071
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5526
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4040
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.