Removing hidden Chr within text, Chr63

USAMax

Well-known Member
Joined
May 31, 2006
Messages
846
Office Version
  1. 365
Platform
  1. Windows
I am using Excel 2010 and cleaning up some data and I have two cells that appear the same but when I compare ActiveCell to ActiveCell.Offset(1,0) they do not match.

When I broke it down I found the mid string that did not match and I got its value using

SndChr = Asc(Mid(ActiveCell.Offset(1, 0), StrVal, 1))
And this returned a value of 63.

I thought I was home free and I could search the string for Chr(63) but it does not find it.

If InStr(1, Cells(x, 1), Asc(63)) > 0 Then

Where am I going wrong?
 
Again agreed.

A sample of the data to be analysed would be an advantage to us all.

I'm fairly sure that this is a specific problem arrising from web derived data.
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This UDF might be a possibility.

I am not a VBa expert, so doubtless it can be improved.

Code:
Function CleanUnicode(rng As Range, _
                      Optional IncludeAscii As Boolean = True, _
                      Optional ShowAsSpace As Boolean = True, _
                      Optional TrimStr As Boolean = False) As String
    Dim n As Long
    Dim strClean As String, strChr As String
    
    strClean = rng
    
    For n = Len(strClean) To 1 Step -1
        strChr = Mid(strClean, n, 1)
        Select Case AscW(strChr)
            Case 8192 To 8207, 8234 To 8239, 8298 To 8303
               If ShowAsSpace Then
                    strClean = Replace(strClean, strChr, " ")
               Else
                    strClean = Replace(strClean, strChr, "")
                    n = Len(strClean)
               End If
        End Select
            
        If IncludeAscii Then
            Select Case Asc(strChr)
                Case 1 To 31, 127, 129, 141.143, 144, 157, 160
                   If ShowAsSpace Then
                        strClean = Replace(strClean, strChr, " ")
                   Else
                        strClean = Replace(strClean, strChr, "")
                        n = Len(strClean)
                   End If
            End Select
        End If
    Next
    If TrimStr Then
        CleanUnicode = WorksheetFunction.Trim(strClean)
    Else
        CleanUnicode = strClean
    End If
End Function

The default substitutes all non-printing characters,unicode spaces and invisible characters with a space, CHAR(32) e.g.
Code:
=CleanUnicode(A2)

The options as booleans are
1/. IncludeAscii > Default = True
2/. ShowAsSpace > Default = True
3/. TrimStr > Default = False

So this removes all non-printing characters and spaces
Code:
=CleanUnicode(A4,,FALSE)
And this trims the result if spaces are chosen
Code:
=CleanUnicode(A4,,FALSE)
i.e. The same as trimming the default function
Code:
=Trim(CleanUnicode(A2))

Try it out with this setup.
You will have to copy this abc??de??f for the string in A2, ExcelJeannie is returning ?s like your problem ...:eeek:
Drag B2:D2 Down

Excel Workbook
ABCD
1StringLengthUDFNew Length
2abc??de ?f10abc de ?f10
3abc??de ?f15abc de ?f 15
4Abcefg7Abc efg7
5Abcefg7Abc efg7
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top