Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to remove leading space

I am just now getting into writing macros so I think this task may be
above me for now. Could some kind person give me a hint on writing a
macro that would check for, and if it exists, remove a single space
that is the first character in a cell from a selected set of cells.

Many thanks in advance for your time
Andrew
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to remove leading space

Andrew
Why use a macro, when a formula will do?
=if(code(A1)=32,right(A1,len(A1)-1),A1)
HTH
Graham Yetton
-----Original Message-----
I am just now getting into writing macros so I think this

task may be
above me for now. Could some kind person give me a hint

on writing a
macro that would check for, and if it exists, remove a

single space
that is the first character in a cell from a selected set

of cells.

Many thanks in advance for your time
Andrew
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to remove leading space

Sub RemoveSpace()
Dim cell As Range

For Each cell In Selection
If Not cell.HasFormula Then
If Not IsEmpty(cell) Then
If Left(cell.Value, 1) = " " Then
cell.Value = Right(cell.Value, _
Len(cell.Value) - 1)
End If
End If
End If
Next
End Sub


--
Regards,
Tom Ogilvy


Andrew wrote in message
om...
I am just now getting into writing macros so I think this task may be
above me for now. Could some kind person give me a hint on writing a
macro that would check for, and if it exists, remove a single space
that is the first character in a cell from a selected set of cells.

Many thanks in advance for your time
Andrew



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to remove leading space

Of course there is also the LTrim(), RTrim(), and Trim()
functions that will wipe out all your leading or trailing
spaces, or both. Very handy when dealing with user forms.

Alex

-----Original Message-----
I am just now getting into writing macros so I think this

task may be
above me for now. Could some kind person give me a hint

on writing a
macro that would check for, and if it exists, remove a

single space
that is the first character in a cell from a selected set

of cells.

Many thanks in advance for your time
Andrew
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to remove leading space

Thank you so much. It works great. This is going to be a REAL
motivator to start learning!


"Tom Ogilvy" wrote in message ...
Sub RemoveSpace()
Dim cell As Range

For Each cell In Selection
If Not cell.HasFormula Then
If Not IsEmpty(cell) Then
If Left(cell.Value, 1) = " " Then
cell.Value = Right(cell.Value, _
Len(cell.Value) - 1)
End If
End If
End If
Next
End Sub


--
Regards,
Tom Ogilvy


Andrew wrote in message
om...
I am just now getting into writing macros so I think this task may be
above me for now. Could some kind person give me a hint on writing a
macro that would check for, and if it exists, remove a single space
that is the first character in a cell from a selected set of cells.

Many thanks in advance for your time
Andrew

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 Leading Space in Cell Gary''s Student Excel Discussion (Misc queries) 0 October 15th 09 04:32 PM
leading and ending space scharee Excel Worksheet Functions 2 October 9th 09 01:37 AM
Macro to remove space at front and end of a cell yhoy Excel Discussion (Misc queries) 2 February 22nd 08 09:53 PM
Remove leading space Karidre Excel Worksheet Functions 4 October 24th 05 03:39 PM
Function to remove a space from text in cell WITHOUT macro?? [email protected] Excel Worksheet Functions 5 May 28th 05 02:28 AM


All times are GMT +1. The time now is 10:13 AM.

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"