Discuss Remove double spaces in the Visual Basic Programming forum on Dev Shed. Remove double spaces Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
Time spent in forums: 5 Days 11 h 25 m 6 sec
Reputation Power: 42
Remove double spaces
I have an Excel file that I imported into an Access database. A lot of the field entries have been found to have " " (double spaces) or extra spaces after the last character. This is causing numerous fields to not group correctly.
Can someone provide me with a VBA script that will remove all double spaces or spaces after the last intended character?
Time spent in forums: 6 Months 2 Weeks 2 Days 6 h 6 m 46 sec
Reputation Power: 8544
Function CleanSpace(ByVal strIn As String) As String
' // Remove leading or trailing spaces
strIn = Trim(strIn)
' // Replace all double space pairings with single spaces
Do While InStr(strIn, " ")
strIn = Replace(strIn, " ", " ")
' // Return the result
CleanSpace = strIn