Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Removing Leading Space in Cell | Excel Discussion (Misc queries) | |||
leading and ending space | Excel Worksheet Functions | |||
Macro to remove space at front and end of a cell | Excel Discussion (Misc queries) | |||
Remove leading space | Excel Worksheet Functions | |||
Function to remove a space from text in cell WITHOUT macro?? | Excel Worksheet Functions |