Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Reformatting text....

Hi.
First, I'm not sure if this is the correct newsgroup for this but I try...

I would like to use excel to reformat text in a musiclibrary.

All performers are located in a textfile like this:

Line 1: ADAMS, BRYAN (ENG) + DENVER, JOHN (USA) + JARRE, JEAN MICHELLE (FRA)
+ THE BEATLES + THE DOORS

I want to acchive a swithching of lastname, firstname so result being like
the following :
(If possible change the letters to capital exept for
the first letter. The language code ex. (ENG) should be kept in capital.)

Bryan Adams (ENG) + John Denver (USA) + Jean Michelle Jarre (FRA) + The
Beatles + The Doors

Is there an expert who knows the answer in this case ?

\T. Tei



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Reformatting text....

Sub Tester()
Dim s As String
s = "ADAMS, BRYAN (ENG) + " & _
"DENVER, JOHN (USA) + JARRE, " & _
"JEAN MICHELLE (FRA) + " & _
"THE BEATLES + THE DOORS"
MsgBox SwitchOrder(s)
End Sub
Public Function SwitchOrder(s)
Dim v As Variant, s1 As String
Dim s2 As String, s3 As String
Dim s4 As String, s5 As String
Dim iloc As Long, iloc1 As Long
v = Split(s, "+")
For i = LBound(v) To UBound(v)
s1 = Trim(v(i))
iloc = InStr(1, s1, "(", vbTextCompare)
If iloc < 0 Then
s5 = Trim(Right(s1, Len(s1) - iloc + 1))
s2 = Left(s1, iloc - 1)
iloc1 = InStr(1, s2, ",", vbTextCompare)
s3 = Trim(Left(s2, iloc1 - 1))
s4 = Trim(Right(s2, Len(s2) - iloc1))
s4 = s4 & " " & s3 & " " & s5
v(i) = s4
End If
Next

SwitchOrder = Join(v, " + ")
End Function

--
Regards,
Tom Ogilvy


"Titten Tei" wrote:

Hi.
First, I'm not sure if this is the correct newsgroup for this but I try...

I would like to use excel to reformat text in a musiclibrary.

All performers are located in a textfile like this:

Line 1: ADAMS, BRYAN (ENG) + DENVER, JOHN (USA) + JARRE, JEAN MICHELLE (FRA)
+ THE BEATLES + THE DOORS

I want to acchive a swithching of lastname, firstname so result being like
the following :
(If possible change the letters to capital exept for
the first letter. The language code ex. (ENG) should be kept in capital.)

Bryan Adams (ENG) + John Denver (USA) + Jean Michelle Jarre (FRA) + The
Beatles + The Doors

Is there an expert who knows the answer in this case ?

\T. Tei




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default Reformatting text....

Hi Tom,

excellent!

Plus the capitalization:

[snip]
SwitchOrder = Join(v, " + ")
Mid(SwitchOrder, 1, 1) = UCase(Mid(SwitchOrder, 1, 1))
For lCnt = 1 To Len(SwitchOrder) - 1
If Mid(SwitchOrder, lCnt, 1) = " " Then
Mid(SwitchOrder, lCnt + 1, 1) = _
UCase(Mid(SwitchOrder, lCnt + 1, 1))
End If
Next
[snip]

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Reformatting text....

I still have some problems with the script.
It fails at the following occassions:

1.If a name does not contain a coutry code (like (USA) f.ex), it will not
switchorder.

2. If a name has country code but not contain a comma - you will get an
error message.

How can this be solved ?

Best regards
T.Tei



"Tom Ogilvy" skrev i melding
...
Sub Tester()
Dim s As String
s = "ADAMS, BRYAN (ENG) + " & _
"DENVER, JOHN (USA) + JARRE, " & _
"JEAN MICHELLE (FRA) + " & _
"THE BEATLES + THE DOORS"
MsgBox SwitchOrder(s)
End Sub
Public Function SwitchOrder(s)
Dim v As Variant, s1 As String
Dim s2 As String, s3 As String
Dim s4 As String, s5 As String
Dim iloc As Long, iloc1 As Long
v = Split(s, "+")
For i = LBound(v) To UBound(v)
s1 = Trim(v(i))
iloc = InStr(1, s1, "(", vbTextCompare)
If iloc < 0 Then
s5 = Trim(Right(s1, Len(s1) - iloc + 1))
s2 = Left(s1, iloc - 1)
iloc1 = InStr(1, s2, ",", vbTextCompare)
s3 = Trim(Left(s2, iloc1 - 1))
s4 = Trim(Right(s2, Len(s2) - iloc1))
s4 = s4 & " " & s3 & " " & s5
v(i) = s4
End If
Next

SwitchOrder = Join(v, " + ")
End Function

--
Regards,
Tom Ogilvy


"Titten Tei" wrote:

Hi.
First, I'm not sure if this is the correct newsgroup for this but I
try...

I would like to use excel to reformat text in a musiclibrary.

All performers are located in a textfile like this:

Line 1: ADAMS, BRYAN (ENG) + DENVER, JOHN (USA) + JARRE, JEAN MICHELLE
(FRA)
+ THE BEATLES + THE DOORS

I want to acchive a swithching of lastname, firstname so result being
like
the following :
(If possible change the letters to capital exept for
the first letter. The language code ex. (ENG) should be kept in capital.)

Bryan Adams (ENG) + John Denver (USA) + Jean Michelle Jarre (FRA) + The
Beatles + The Doors

Is there an expert who knows the answer in this case ?

\T. Tei






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
retain custom date format "text" when pasting or reformatting data frustrated worker Excel Discussion (Misc queries) 2 October 28th 09 06:03 PM
Help With Reformatting Robert Excel Discussion (Misc queries) 0 July 23rd 09 02:56 PM
Change default text color without reformatting the sheet. Monorail Central Excel Discussion (Misc queries) 1 January 15th 09 01:28 AM
Reformatting text in cells RFJ Excel Worksheet Functions 3 April 9th 07 06:41 PM
Reformatting dates as text AmyTaylor Excel Worksheet Functions 1 November 11th 05 11:25 AM


All times are GMT +1. The time now is 09:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"