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
Bookmarks