• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to clear out an ASCII 1 from data string?

Eloise T

Active Member
I receive Excel spreadsheets weekly from technicians submitting their work. Since these sheets are often a mess I use:
Code:
.Value = .Parent.Evaluate(Replace("IF(#>"""",TRIM(CLEAN(#)),"""")", "#", .Address))

to help clean up the data.

I started with TRIM which removes leading and trailing spaces, then as an added measure I added CLEAN to remove leading and trailing ASCII characters 0-31. See sanitized attachment.

Based on cell D3, the ASCII character is a 1 which is SOH (Start of Heading) and should be removed by CLEAN, but after running TRIM and CLEAN the ASCII 1 persists. Any suggests for adjusting the formula to get rid of all ASCII 1s in the future?

Thank you for any assistance.
 

Attachments

  • ASCII code 1.xlsm
    30.6 KB · Views: 9
Your formula in D9 is incorrect
It should be =CODE(LEFT(D3,1))

Hence the space is not Asciii code 1 but Asciii code 160

To fix it use: =SUBSTITUTE(D3,CHAR(160),"")
 
Hi !

The cell D3 first character is the ASCII #160 but as for data
from the Web this character can replace any space so the
better is to convert it as a space before the TRIM function
in case of other #160 within the text :​
Code:
Sub Demo1()
    With Sheet2.[A2].CurrentRegion.Columns(4).Rows
        With .Item("2:" & .Count)
             .Value = .Parent.Evaluate("IF({1},TRIM(SUBSTITUTE(" & .Address & ",CHAR(160),"" "")))")
        End With
    End With
End Sub
Do you like it ? So thanks to click on bottom right Like !
 
Thanks a lot. I didn't get it completely. Forgive me
Can you give me more details?

Why using IF .. I have tried this line and it works fine without using the IF part
Code:
.Value = .Parent.Evaluate("TRIM(SUBSTITUTE(" & .Address & ",CHAR(160),"" ""))")
 
As in the initial attachment there is only a single row
- which is a bit poor and not logical with the IF in its code ! -
so just copy down the cell D3 and retry without IF

For only one cell no needs an array but from two an array is expected !

So when Evaluate returns a single value as an array is expected then
adding IF with an array in its formula means « Hey dude, I need an array ! »
 
Yes you're right as I just test both and each works !

I remember I needed an IF with a previous formula
but when I thought about char #160 replacing any space
I updated the formula and I didn't retry without the IF.

But remember this trick 'cause one day you will need it !
 
Back
Top