Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ram Ram is offline
external usenet poster
 
Posts: 138
Default removing leading and trailing spaces

I have excel worksheet with some data in the cells. But in each cell the data
has leading and traliling spaces. I don't have any hidden characters. I save
this excel file as CSV file but CSV file is preserving these spaces. Does any
one can help me about the VBA macro how to remove the leading and trailing
spaces from all cells when I create the csv file from the excel file. The
excel should not be modified in anyway.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 256
Default removing leading and trailing spaces

Note there's also a worksheet function TRIM() that has the same
functionality as the VBA one.



Public Sub leadingSpaces()
Dim rng As Excel.Range
Dim wsh As Excel.Range

Application.ScreenUpdating = False

Set wsh = Application.ActiveSheet.UsedRange

For Each rng In wsh
rng.Value = Trim(rng.Value)
Next rng

Application.ScreenUpdating = True
End Sub



On Oct 31, 5:18 pm, Ram wrote:
I have excel worksheet with some data in the cells. But in each cell the data
has leading and traliling spaces. I don't have any hidden characters. I save
this excel file as CSV file but CSV file is preserving these spaces. Does any
one can help me about the VBA macro how to remove the leading and trailing
spaces from all cells when I create the csv file from the excel file. The
excel should not be modified in anyway.



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
Removing trailing spaces in a spreadsheet Kamran Excel Discussion (Misc queries) 6 December 8th 06 09:40 PM
Removing leading/trailing spaces Chuda Excel Discussion (Misc queries) 2 September 12th 06 04:20 PM
REMOVING TRAILING SPACES Tris Excel Discussion (Misc queries) 5 August 29th 06 03:36 PM
How keep Leading/Trailing spaces when save in Excel? jorgejulio Excel Discussion (Misc queries) 0 August 1st 06 09:49 PM
Delete leading or trailing blank spaces in cell - an example DataFreakFromUtah Excel Programming 2 September 16th 04 10:04 PM


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