+ Reply to Thread
Results 1 to 2 of 2

Remove Leading Spaces

  1. #1
    Forum Contributor
    Join Date
    04-25-2006
    Posts
    215

    Remove Leading Spaces

    I have several columns of dates. The dates are formatted as text with a leading space before each one. I'd like to be able to highlight the range, and have the leading spaces removed and the format set as mm/dd/yy. I have the following, but it does not allow me to highlight the range. As you can see, it moves down the column, but it doesn't handle blank cells and quits when it encounters one. Thanks for any help.

    Sub FormatDate()
    Dim cell As Range

    Set cell = Sheet1.Range("A1")

    Do
    cell.Value = Trim(cell)
    cell.NumberFormat = "mm/dd/yyyy"
    Set cell = cell.Offset(1, 0)
    Loop Until cell.Value = ""

    End Sub

  2. #2
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    Sub FormatDate()
    For Each cell In Selection
    cell.Value = Trim(cell)
    cell.NumberFormat = "mm/dd/yyyy"
    Next cell

    End Sub
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1