Results 1 to 9 of 9

Deleting leading and trailing spaces from a number

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Deleting leading and trailing spaces from a number

    I am using the following code to import an excel file into an existing sheet. The problem I am having is the way some of the cells are being imported. Some of the cells have spaces before and after the number. I need to delete the leading and trailing spaces for each cell affected. Is there a code I can incorporate to do this? BTW…the columns effected are columns F & G. Thanks

    Sub MuniAnalysis()
    
    Dim i               As Long
    Dim j               As Long
    Dim n               As Long
    Dim LastRow         As Long
    Dim Prompt          As String
    Dim Title           As String
    Dim Path            As String
    Dim SourceWkb       As Workbook
    Dim DestinationWkb  As Workbook
    Dim Rng             As Range
    
        Set DestinationWkb = ThisWorkbook
        
        Prompt = "Select the Excel file to process."
        Path = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , Prompt)
        If Path = "False" Then
            GoTo ExitSub:
        End If
    
        Application.DisplayAlerts = False
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        
        Workbooks.Open Filename:=Path
        
        Set SourceWkb = ActiveWorkbook
     
            Range("A1").Select
              
            Set Rng = Selection.CurrentRegion
                Rng.Resize(Rng.Rows.Count, 16).Copy
    
            With DestinationWkb.Worksheets("Muni Analysis")
                LastRow = .Range("A" & Rows.Count).End(xlUp).Row
                .Range("A" & LastRow + 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, _
                    SkipBlanks:=False, Transpose:=False
            End With
        
        SourceWkb.Close SaveChanges:=False
    
    ExitSub:
        
        Application.DisplayAlerts = True
        Application.EnableEvents = True
        Application.ScreenUpdating = True
        Application.StatusBar = False
        
        Set SourceWkb = Nothing
        
    End Sub
    Last edited by maacmaac; 03-31-2009 at 10:35 PM.

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