#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 12
Default TRIM function

Greetings!

I'm using Excel 2007 and would like to apply the TRIM funtion to the entire
spreadsheet. I know how to do it for a given cell and then copy it to the
rest of the column but would like to do a whole spreadsheet at the same time
if possible.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default TRIM function

Sub TrimData()

For each cell In Activesheet.usedrange

cell.Value = Trim(cell.Value)
Next cell
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Chimelle" wrote in message
...
Greetings!

I'm using Excel 2007 and would like to apply the TRIM funtion to the
entire
spreadsheet. I know how to do it for a given cell and then copy it to the
rest of the column but would like to do a whole spreadsheet at the same
time
if possible.

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,393
Default TRIM function

1) On Sheet2 in A1, enter =TRIM(Sheet1!A1)
2) Copy this as far to the right and down as needed to capture all used
cells on Sheet1
3) Select all of Sheet2 used cells (CTRL+A or click the box where column
and row headers meet (to the left of A; above 1)
4) Use Copy
5) With the cells still selected use Edit | Paste Special with Values
checked
6) Now Sheet2 has values and Sheet1 could be deleted - but do double check
first.
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Chimelle" wrote in message
...
Greetings!

I'm using Excel 2007 and would like to apply the TRIM funtion to the
entire
spreadsheet. I know how to do it for a given cell and then copy it to the
rest of the column but would like to do a whole spreadsheet at the same
time
if possible.

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default TRIM function

That might not do exactly what the OP asked for. The VBA Trim function
**only** removes spaces from the left and right sides of the text... the
worksheet TRIM function collapses multiple internal spaces down to single
spaces as well. You could modify your code like this (if you want to remain
wholly within VBA) to match this functionality....

Sub TrimData()
Dim CellText As String
Dim Cell As Range
For each Cell In Activesheet.UsedRange
CellText = Cell.Value
CellText = Trim(CellText)
Do While InStr(CellText, " ")
CellText = Replace(CellText, " ", " ")
Loop
Next
Cell.Value = CellText
End Sub

or, if you don't mind reaching out to the worksheet world, like this...

Sub TrimData()
Dim Cell As Range
For each Cell In Activesheet.UsedRange
Cell.Value = Application.WorksheetFunction.Trim(Cell.Value)
Next
End Sub

Rick



"Bob Phillips" wrote in message
...
Sub TrimData()

For each cell In Activesheet.usedrange

cell.Value = Trim(cell.Value)
Next cell
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Chimelle" wrote in message
...
Greetings!

I'm using Excel 2007 and would like to apply the TRIM funtion to the
entire
spreadsheet. I know how to do it for a given cell and then copy it to
the
rest of the column but would like to do a whole spreadsheet at the same
time
if possible.

Thanks!




  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default TRIM function

but then it again it might.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick Rothstein (MVP - VB)" wrote in
message ...
That might not do exactly what the OP asked for. The VBA Trim function
**only** removes spaces from the left and right sides of the text... the
worksheet TRIM function collapses multiple internal spaces down to single
spaces as well. You could modify your code like this (if you want to
remain wholly within VBA) to match this functionality....

Sub TrimData()
Dim CellText As String
Dim Cell As Range
For each Cell In Activesheet.UsedRange
CellText = Cell.Value
CellText = Trim(CellText)
Do While InStr(CellText, " ")
CellText = Replace(CellText, " ", " ")
Loop
Next
Cell.Value = CellText
End Sub

or, if you don't mind reaching out to the worksheet world, like this...

Sub TrimData()
Dim Cell As Range
For each Cell In Activesheet.UsedRange
Cell.Value = Application.WorksheetFunction.Trim(Cell.Value)
Next
End Sub

Rick



"Bob Phillips" wrote in message
...
Sub TrimData()

For each cell In Activesheet.usedrange

cell.Value = Trim(cell.Value)
Next cell
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Chimelle" wrote in message
...
Greetings!

I'm using Excel 2007 and would like to apply the TRIM funtion to the
entire
spreadsheet. I know how to do it for a given cell and then copy it to
the
rest of the column but would like to do a whole spreadsheet at the same
time
if possible.

Thanks!








  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default TRIM function

True (which I implied by saying it might not)... all I was trying to do was
alert the OP to the possibility that it might not do what was anticipated of
it if the data contained multiple internal spaces (and to offer a work
around if one was needed).

Rick


"Bob Phillips" wrote in message
...
but then it again it might.

"Rick Rothstein (MVP - VB)" wrote in
message ...
That might not do exactly what the OP asked for. The VBA Trim function
**only** removes spaces from the left and right sides of the text... the
worksheet TRIM function collapses multiple internal spaces down to single
spaces as well. You could modify your code like this (if you want to
remain wholly within VBA) to match this functionality....

Sub TrimData()
Dim CellText As String
Dim Cell As Range
For each Cell In Activesheet.UsedRange
CellText = Cell.Value
CellText = Trim(CellText)
Do While InStr(CellText, " ")
CellText = Replace(CellText, " ", " ")
Loop
Next
Cell.Value = CellText
End Sub

or, if you don't mind reaching out to the worksheet world, like this...

Sub TrimData()
Dim Cell As Range
For each Cell In Activesheet.UsedRange
Cell.Value = Application.WorksheetFunction.Trim(Cell.Value)
Next
End Sub

Rick



"Bob Phillips" wrote in message
...
Sub TrimData()

For each cell In Activesheet.usedrange

cell.Value = Trim(cell.Value)
Next cell
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Chimelle" wrote in message
...
Greetings!

I'm using Excel 2007 and would like to apply the TRIM funtion to the
entire
spreadsheet. I know how to do it for a given cell and then copy it to
the
rest of the column but would like to do a whole spreadsheet at the same
time
if possible.

Thanks!






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
Trim Function Saxman[_2_] Excel Discussion (Misc queries) 7 August 2nd 07 01:20 AM
TRIM function fitou_learn[_2_] New Users to Excel 2 June 12th 07 11:06 AM
trim function [email protected] Excel Worksheet Functions 3 December 30th 05 03:00 AM
Trim Function Steved Excel Worksheet Functions 5 August 4th 05 11:06 PM
How to use TRIM function Sky Warren Excel Worksheet Functions 3 January 8th 05 05:06 PM


All times are GMT +1. The time now is 03:57 PM.

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

About Us

"It's about Microsoft Excel"