Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VB Script To replace space with nothing

Hey ,

is it possible to have a VB script that will search out a rang
that i specified 2 elimnate spacing between text in a cell .. fo
example .. first name and replace with firstname ?
i have done this with a macro ...
but i would like it as a script .. the for the macro was
as follows :
' Macro1 Macro
' This is To Eliminate Spaces Within Headers
'
' Keyboard Shortcut: Ctrl+h
'
Range("A1:Y1").Select
Range("Y1").Activate
ActiveWorkbook.Names.Add Name:="Headers", RefersToR1C1:= _
"=Sheet1!R1C1:R1C23"

Selection.Replace What:="last digit", Replacement:="lastdigit"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="first name", Replacement:="firstname"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="last name", Replacement:="lastname"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="job title", Replacement:="jobtitle"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="toll free", Replacement:="tollfree"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="post code", Replacement:="postcode"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="id number", Replacement:="idnumber"
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False


End Sub
:confused

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VB Script To replace space with nothing

Jon,

Just go through the data and for each cell use Replace like

replace(A1," ","")

' Macro1 Macro
' This is To Eliminate Spaces Within Headers
'
' Keyboard Shortcut: Ctrl+h
'
ActiveWorkbook.WorkSheets("Sheet1").Range("A1:Y1") .Name = Headers"

For Each cell In Range("Headers")
Replace (cell," ","")
Next cell
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"JonEx2k2 " wrote in message
...
Hey ,

is it possible to have a VB script that will search out a range
that i specified 2 elimnate spacing between text in a cell .. for
example .. first name and replace with firstname ?
i have done this with a macro ...
but i would like it as a script .. the for the macro was
as follows :
' Macro1 Macro
' This is To Eliminate Spaces Within Headers
'
' Keyboard Shortcut: Ctrl+h
'
Range("A1:Y1").Select
Range("Y1").Activate
ActiveWorkbook.Names.Add Name:="Headers", RefersToR1C1:= _
"=Sheet1!R1C1:R1C23"

Selection.Replace What:="last digit", Replacement:="lastdigit",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="first name", Replacement:="firstname",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="last name", Replacement:="lastname",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="job title", Replacement:="jobtitle",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="toll free", Replacement:="tollfree",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="post code", Replacement:="postcode",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False

Selection.Replace What:="id number", Replacement:="idnumber",
LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False


End Sub



---
Message posted from http://www.ExcelForum.com/



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
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
How to Replace ? With Space Hardeep kanwar Excel Worksheet Functions 3 March 27th 09 06:56 PM
replace space sham Excel Worksheet Functions 4 June 16th 07 04:29 PM
How do I write a script to add space between numbers in a column? [email protected] Excel Discussion (Misc queries) 4 May 15th 07 04:53 PM
Replace (') to space Avadivelan TCS Excel Worksheet Functions 1 September 8th 06 02:07 PM


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