Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete blank spaces in string. (Trim does not do it).

Status
Not open for further replies.

jdttek

Technical User
May 8, 2002
112
US
Hi
I have scanned numeric data off of a paper statement into an Excel Spreadsheet (using TextBridge / OCR). Surprisingly, all characters are consistently recognized and placed in the correct column!

Problem is, on occassion, a blank space is inserted between characters in the string (e.g. 1234 imports as 12 34). I have tried using TRIM to eliminate this space but it does not work for a single space. I am looking for a way to test the string and delete any spaces that may exist (back to 1234). Any solutions would be greatly appreciated.

Thanks
JDTTEK
 
You can use the following function:

Function NoSpace(inString)
For Counter = 1 To Len(inString)
If (Mid(inString, Counter, 1) <> &quot; &quot;) Then
outString = outString + Mid(inString, Counter, 1)
End If
Next Counter
NoSpace = outString
End Function

Then, reference this function in your VBA code as follows:
aString = NoSpace(aString)

-vbMax
 
You can use the replace function:

Code:
strText = Replace(strText, &quot; &quot;, &quot;&quot;)
 
Hi jdttek,

To remove ALL spaces from a string (in A1), use:

Code:
=SUBSTITUTE(A1,&quot; &quot;,&quot;&quot;)

.. or, in code, to fix cell A1 in place ..

Code:
[A1] = WorksheetFunction.Substitute([A1],&quot; &quot;,&quot;&quot;)

Enjoy,
Tony
 
Or, for the whole 1st worksheet:

[tt]Worksheets(1).UsedRange.Replace What:=&quot; &quot;, Replacement:=&quot;&quot;, LookAt:=xlPart[/tt]

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top