Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default LTRIM Problem

I am trying to trim the leading spaces from all text in Column U.
I have have the following code but when I run it nothing happens (the
leading spaces are still there). I've tried both LTRIM and TRIM but neither
seems to work.
What am I missing?

Dim Rng as Range
Sheets("Raw Projections").Select
For Each Rng In ActiveSheet.Range("U6:U500")
Rng.Value = LTrim(Rng.Value)
Next Rng

Matt

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default LTRIM Problem

Hi Matt,
Try including this before the loop

Selection.Replace What:=Chr(160), Replacement:=Chr(32), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

For more information see:
http://www.mvps.org/dmcritchie/excel/join.htm#trimall

Char(160) is the HTML   (non-breaking space)

But if you look at the macro TRIMALL macro you will see some additional
code which will make the macro run faster.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"mtsark" wrote in message ...
I am trying to trim the leading spaces from all text in Column U.
I have have the following code but when I run it nothing happens (the
leading spaces are still there). I've tried both LTRIM and TRIM but neither
seems to work.
What am I missing?

Dim Rng as Range
Sheets("Raw Projections").Select
For Each Rng In ActiveSheet.Range("U6:U500")
Rng.Value = LTrim(Rng.Value)
Next Rng

Matt



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

Your code works fine for me.


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


"mtsark" wrote in message
...
I am trying to trim the leading spaces from all text in Column

U.
I have have the following code but when I run it nothing

happens (the
leading spaces are still there). I've tried both LTRIM and

TRIM but neither
seems to work.
What am I missing?

Dim Rng as Range
Sheets("Raw Projections").Select
For Each Rng In ActiveSheet.Range("U6:U500")
Rng.Value = LTrim(Rng.Value)
Next Rng

Matt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default LTRIM Problem

Thanks guys I modified to code to the following and it worked great.

Sheets("Raw Projections").Range("U6:U500").Select
Selection.Replace What:=Chr(160), Replacement:=Chr(32), LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False
For Each Rng In ActiveSheet.Range("U6:U500")
Rng.Value = LTrim(Rng.Value)
Next Rng


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
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
I can't seem to use RTRIM or LTRIM in Excel 2002. I want to trim. Pam New Users to Excel 3 December 2nd 04 12:08 AM
How do I apply LTRIM to entire Sheet? D[_6_] Excel Programming 2 August 11th 04 11:04 AM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM
LTrim Dave B[_3_] Excel Programming 1 July 18th 03 07:40 AM


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