Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That's a good point Tom. I've made the corrections below.
Cheers, Sub DeleteTrailingBlankSpacesOnTheRight() 'Deletes trailing blank spaces on the right of a string Dim cell As Range Dim rng As Range On Error Resume Next Set rng = Selection.SpecialCells(xlCellTypeConstants, xlTextValues) For Each cell In Intersect(Selection, rng) cell.Value = RTrim(cell.Value) Next cell End Sub Sub DeleteLeadingBlankSpacesOnTheLeft() 'Deletes leading blank spaces on the left of a string Dim cell As Range Dim rng As Range On Error Resume Next Set rng = Selection.SpecialCells(xlCellTypeConstants, xlTextValues) For Each cell In Intersect(Selection, rng) cell.Value = LTrim(cell.Value) Next cell End Sub Sub DeleteBlankSpacesOnTheLeftAndRight() 'Deletes blank spaces to the left and right of a string Dim cell As Range On Error Resume Next Dim rng As Range Set rng = Selection.SpecialCells(xlCellTypeConstants, xlTextValues) For Each cell In Intersect(Selection, rng) cell.Value = Trim(cell.Value) Next cell End Sub Function RemoveTrailingBlankSpacesOnTheRight(TargetCell As Range) As String 'Removes trailing blank spaces on the right of a string On Error Resume Next RemoveTrailingBlankSpacesOnTheRight = RTrim(TargetCell.Value) End Function Function RemoveLeadingBlankSpacesOnTheLeft(TargetCell As Range) As String 'Removes leading blank spaces on the left of a string On Error Resume Next RemoveLeadingBlankSpacesOnTheLeft = LTrim(TargetCell.Value) End Function Function RemoveBlankSpacesOnTheLeftAndRight(TargetCell As Range) As String 'Removes blank spaces to the left and right of a string On Error Resume Next RemoveBlankSpacesOnTheLeftAndRight = Trim(TargetCell.Value) End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Deleting leading spaces in a cell | Excel Discussion (Misc queries) | |||
how do I remove leading spaces and leave the remianing spaces w | Excel Worksheet Functions | |||
Removing leading/trailing spaces | Excel Discussion (Misc queries) | |||
How keep Leading/Trailing spaces when save in Excel? | Excel Discussion (Misc queries) | |||
Strip leading spaces from cell | Excel Worksheet Functions |