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. :-) -
'Uses the Excel VBA split function
-
Sub MyExcelSplitCells()
-
Dim TempArray As Variant
-
Dim rwIndex, colIndex
-
With Sheet3
-
For rwIndex = 1 To .UsedRange.Rows.Count
-
TempArray = mySplit(Trim(.Cells(rwIndex, 1).Text))
-
For colIndex = 2 To UBound(TempArray) + 2
-
.Cells(rwIndex, colIndex).Value = TempArray(colIndex - 2)
-
Next
-
Next
-
End With
-
End Sub
-
Function mySplit(str As String) As Variant
-
ReDim myArray(0)
-
Dim counter As Integer
-
counter = 0
-
For x = 1 To Len(str)
-
Select Case Mid(str, x, 1)
-
Case ",", " " '".", "-"
-
If Len(myArray(counter)) > 0 Then
-
counter = counter + 1
-
ReDim Preserve myArray(counter)
-
End If
-
-
Case Else
-
myArray(counter) = myArray(counter) + Mid(str, x, 1)
-
End Select
-
Next
-
mySplit = myArray
-
End Function
-
the Raw Data looks like: -
AShok Kumar, Mr. Pandi
-
Aanei, Mr. Paul
-
Aarthi, Mrs. Aravamudhan
-
Abbott, Mr. Neil
-
Abcouwer, Mr. Eric
-
Abd Manaf, Mrs. Fazilah
-
Abdul Aziz, Mr. Ahmed
-
Abdulgapul, Mr. Al-Ameen B
-
Abdullaeva, Miss Roziya
-
Abhishek, Mr. Banchhor
-
Abhishek, Mr. Roy
-
Abisamra, Mr. Atef
-
Able, Mr. Klaus
-
Abraham, Mr. Lionel
-
Achuth Rao, Mr. Subramania Rao
-
Acosta, Mr. Ernesto F.
-
Adefioye, Mr. William
-
Adeline Jenitha, Ms. Wilfred
-
Adeyemi, Mr. Peter Adekunle (Peter)
-
Adkinson, Mr. Desmond John
-
Ageev, Mr. Fedor Borisovitch (Fedor)
-
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,
11 1627 QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Check This : -
Dim sSQL As String
-
sSQL = "AShok Kumar, Mr. Pandi"
-
-
Dim tarr
-
Dim i As Integer
-
Dim FName As String
-
Dim LName As String
-
Dim Title As String
-
'
-
tarr = Split(sSQL, ",")
-
FName = tarr(0)
-
'
-
sSQL = Replace(sSQL, FName, "")
-
sSQL = Replace(sSQL, ",", "")
-
sSQL = Trim(sSQL)
-
'
-
tarr = Split(sSQL, " ")
-
'
-
Title = tarr(0)
-
LName = ""
-
For i = 1 To UBound(tarr)
-
LName = LName & " " & Trim(tarr(i))
-
Next
-
MsgBox Title & " " & FName & LName
-
'
-
Regards
Veena
Question: Do you trust the data to always include a title? This will make a difference to the logic.
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,
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
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
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Just replace your MySplit function: -
Function mySplit(sSQL As String) As Variant
-
Dim tarr
-
Dim i As Integer
-
Dim FName As String
-
Dim LName As String
-
Dim Title As String
-
Dim NewArr(0 to 2) As String
-
'
-
tarr = Split(sSQL, ",")
-
FName = tarr(0)
-
'
-
sSQL = Replace(sSQL, FName, "")
-
sSQL = Replace(sSQL, ",", "")
-
sSQL = Trim(sSQL)
-
'
-
tarr = Split(sSQL, " ")
-
'
-
Title = tarr(0)
-
LName = ""
-
For i = 1 To UBound(tarr)
-
LName = LName & " " & Trim(tarr(i))
-
Next
-
NewArr(0) = Title
-
NewArr(1) = FName
-
NewArr(2) = LName
-
mySplit = NewArr
-
End Function
-
-
You have used "str" as a variable name. It is a Reserverd Word and should be avoided using it as a variable.
Regards
Veena
No, there are also some, who have a Doctor as Title.
My question was whether it ever has no title.
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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,
|
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
|
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,
|
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...
|
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" >
| |
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.
|
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
|
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
|
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
|
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>;
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |