Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Inserting and deleting spaces with a macro


Ok,
so I have names in a column which I want to both insert a space afte
a "," and then delete everything after the second word space. i.e
James,Patrick Coogan needs to be
James, Patrick
Can this be done?
Thanks in advance
You guys have been very patient and I very much appreciate all th
help.
Patrick:

--
crowdx4
-----------------------------------------------------------------------
crowdx42's Profile: http://www.excelforum.com/member.php...fo&userid=3774
View this thread: http://www.excelforum.com/showthread.php?threadid=57405

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Inserting and deleting spaces with a macro

Assuming the only comma and space are as indicated, this UDF should do it.

Public Function FixName(argRange As Range) As String
FixName = Replace(Split(argRange, " ")(0), ",", ", ")
End Function

You should add error checking to ensure that argRange is a single cell.

NickHK

"crowdx42" wrote in
message ...

Ok,
so I have names in a column which I want to both insert a space after
a "," and then delete everything after the second word space. i.e
James,Patrick Coogan needs to be
James, Patrick
Can this be done?
Thanks in advance
You guys have been very patient and I very much appreciate all the
help.
Patrick:)


--
crowdx42
------------------------------------------------------------------------
crowdx42's Profile:

http://www.excelforum.com/member.php...o&userid=37749
View this thread: http://www.excelforum.com/showthread...hreadid=574054



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Inserting and deleting spaces with a macro


=LEFT(A1,FIND(",",A1,1)-1) & ", " & MID(A1,FIND(",",A1,1)+1,(FIND("
",A1,1)-FIND(",",A1,1)))

or

Public Function CleanUpString(nameInCell As String) As String

CleanUpString = Left(nameInCell, InStr(1, nameInCell, ",",
vbTextCompare) - 1) & ", " & Mid(nameInCell, InStr(1, nameInCell, ",",
vbTextCompare) + 1, (InStr(1, nameInCell, " ", vbTextCompare) - InStr(1,
nameInCell, ",", vbTextCompare)))

End Function



"crowdx42" schreef
in bericht ...

Ok,
so I have names in a column which I want to both insert a space after
a "," and then delete everything after the second word space. i.e
James,Patrick Coogan needs to be
James, Patrick
Can this be done?
Thanks in advance
You guys have been very patient and I very much appreciate all the
help.
Patrick:)


--
crowdx42
------------------------------------------------------------------------
crowdx42's Profile:
http://www.excelforum.com/member.php...o&userid=37749
View this thread: http://www.excelforum.com/showthread...hreadid=574054



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Inserting and deleting spaces with a macro


"NickHK" schreef in bericht
...
Assuming the only comma and space are as indicated, this UDF should do it.

Public Function FixName(argRange As Range) As String
FixName = Replace(Split(argRange, " ")(0), ",", ", ")
End Function


Way to go.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Inserting and deleting spaces with a macro

You can use worksheet functions to do the same.

=CONCATENATE(LEFT(A1,FIND(",",A1,1))," ",MID(A1,FIND(",",A1,1)+2,FIND("
",A1,FIND(",",A1))))

if A1 contains the name.

"crowdx42" wrote in
message ...

Ok,
so I have names in a column which I want to both insert a space after
a "," and then delete everything after the second word space. i.e
James,Patrick Coogan needs to be
James, Patrick
Can this be done?
Thanks in advance
You guys have been very patient and I very much appreciate all the
help.
Patrick:)


--
crowdx42
------------------------------------------------------------------------
crowdx42's Profile:
http://www.excelforum.com/member.php...o&userid=37749
View this thread: http://www.excelforum.com/showthread...hreadid=574054





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Inserting and deleting spaces with a macro

Hi Try this one
A1: James,Patrick Coogan
B1: =SUBSTITUTE(LEFT(A1,FIND(" ",A1)),",",", ")

"crowdx42" wrote:


Ok,
so I have names in a column which I want to both insert a space after
a "," and then delete everything after the second word space. i.e
James,Patrick Coogan needs to be
James, Patrick
Can this be done?
Thanks in advance
You guys have been very patient and I very much appreciate all the
help.
Patrick:)


--
crowdx42
------------------------------------------------------------------------
crowdx42's Profile: http://www.excelforum.com/member.php...o&userid=37749
View this thread: http://www.excelforum.com/showthread...hreadid=574054


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Inserting and deleting spaces with a macro

You could select your range
edit|replace
what: (spacebar)* (two characters total)
with: (leave blank)
replace all

edit|Replace
what: ,
with: ,(spacebar)
replace all

If you needed code:
Option Explicit
Sub testme()
With Selection
.Replace What:=" *", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
.Replace What:=",", Replacement:=", ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
End With
End Sub


crowdx42 wrote:

Ok,
so I have names in a column which I want to both insert a space after
a "," and then delete everything after the second word space. i.e
James,Patrick Coogan needs to be
James, Patrick
Can this be done?
Thanks in advance
You guys have been very patient and I very much appreciate all the
help.
Patrick:)

--
crowdx42
------------------------------------------------------------------------
crowdx42's Profile: http://www.excelforum.com/member.php...o&userid=37749
View this thread: http://www.excelforum.com/showthread...hreadid=574054


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Inserting and deleting spaces with a macro


Excellent stuff,
Dave's worked perfect for me, saved me a lot of time.
Thanks so much :)
Patrick


--
crowdx42
------------------------------------------------------------------------
crowdx42's Profile: http://www.excelforum.com/member.php...o&userid=37749
View this thread: http://www.excelforum.com/showthread...hreadid=574054

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
Matching names and inserting spaces ILunacy Excel Worksheet Functions 0 February 15th 10 06:15 PM
Matching names and inserting spaces ILunacy Excel Worksheet Functions 3 February 15th 10 03:17 PM
Deleting spaces GARY Excel Discussion (Misc queries) 5 August 17th 08 09:35 PM
Inserting/Deleting Spaces carl Excel Worksheet Functions 4 April 22nd 05 06:25 PM
Excel – Macro Problem – Inserting, Appending Data, Deleting Aussiexcel[_3_] Excel Programming 0 August 25th 04 07:48 AM


All times are GMT +1. The time now is 10:38 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"