Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Removing preceeding spaces

When opening specific text documents in excel, the text is
captured with 6 or 7 preceeding spaces (this is
expected). I'm looking for a macro that will remove only
the preceeding spaces, but not touch any spaces that
appear after the first character of text. Is there a
macro that can remove these? I have tried to setup a
macro that copies and pastes values...etc. but to no
avail. The spaces are always carried along.

Thanks for your suggestions.

wjd01
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Removing preceeding spaces

from vba help for trim
LTrim, RTrim, and Trim Functions
Returns a Variant (String) containing a copy of a specified string without
leading spaces (LTrim), trailing spaces (RTrim), or both leading and
trailing spaces (Trim).

Syntax

LTrim(string)

RTrim(string)

Trim(string)

The required string argument is any valid string expression. If string
contains Null, Null is returned.


--
Don Guillett
SalesAid Software

"wjd01" wrote in message
...
When opening specific text documents in excel, the text is
captured with 6 or 7 preceeding spaces (this is
expected). I'm looking for a macro that will remove only
the preceeding spaces, but not touch any spaces that
appear after the first character of text. Is there a
macro that can remove these? I have tried to setup a
macro that copies and pastes values...etc. but to no
avail. The spaces are always carried along.

Thanks for your suggestions.

wjd01



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Removing preceeding spaces

The LTrim function will trim only spaces on the left, leaving the
rest intact. Try something like


Sub AAA()
Dim Rng As Range
For Each Rng In Range("A1:A10") ' << CHANGE Range
Rng.Value = LTrim(Rng.Text)
Next Rng
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com







"wjd01" wrote in message
...
When opening specific text documents in excel, the text is
captured with 6 or 7 preceeding spaces (this is
expected). I'm looking for a macro that will remove only
the preceeding spaces, but not touch any spaces that
appear after the first character of text. Is there a
macro that can remove these? I have tried to setup a
macro that copies and pastes values...etc. but to no
avail. The spaces are always carried along.

Thanks for your suggestions.

wjd01



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Removing preceeding spaces

Thanks for the suggestion. It worked great.

wjd01


-----Original Message-----
The LTrim function will trim only spaces on the left,

leaving the
rest intact. Try something like


Sub AAA()
Dim Rng As Range
For Each Rng In Range("A1:A10") ' << CHANGE Range
Rng.Value = LTrim(Rng.Text)
Next Rng
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com







"wjd01" wrote in message
...
When opening specific text documents in excel, the text

is
captured with 6 or 7 preceeding spaces (this is
expected). I'm looking for a macro that will remove

only
the preceeding spaces, but not touch any spaces that
appear after the first character of text. Is there a
macro that can remove these? I have tried to setup a
macro that copies and pastes values...etc. but to no
avail. The spaces are always carried along.

Thanks for your suggestions.

wjd01



.

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 Spaces Gary Excel Discussion (Misc queries) 15 January 9th 08 01:14 PM
removing all spaces jamesea Excel Discussion (Misc queries) 4 May 27th 07 02:18 PM
Removing spaces in cell Tom Excel Worksheet Functions 4 January 30th 07 12:48 AM
removing spaces Claus Massmann Excel Discussion (Misc queries) 12 March 30th 06 02:23 AM
removing spaces between the numbers martin Excel Discussion (Misc queries) 7 December 14th 05 10:18 AM


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