Weird character causing error when trying to import Excel sheet

0

This character " " (which isn't visible once I save this comment). It looks like 2 brackets pushed together, touching to form a tall rectangle. []

An exported Excel sheet from Filemaker (old version) causes an error and stop import at a certain row that has a recurring character.

I can only see the weird character when I copy/paste the cell contents into Wordpad. The line contains 2 unseen line break markup tags, and between them is . Whenever this happens I have to edit the contents in Wordpad, paste and then it works. Keeps showing up every few rows.

Second question. Is there a way to search for this in Excel and delete all of them?

Adam White

Posted 2018-01-04T20:18:30.613

Reputation: 1

Can you isolate the "junk" character in a cell by removing any good ones ?? – Gary's Student – 2018-01-04T20:24:33.120

I isolated that character and searched the Excel file for it, but it turned up 75,000 blank cells., and not the problem cell in question. – Adam White – 2018-01-04T20:34:50.800

The two brackets (like ‘[]’) are Excel’s way to display a character that it can’t display in the current font. So it really doesn’t give much info beyond ‘a strange character’. – Aganju – 2018-01-05T03:22:48.750

Answers

1

We need to identify the miscreant character first and then remove it.

First put the following User Defined Function in a standard module:

Public Function WhatsIn(s As String) As String
    Dim msg As String, i As Long, L As Long

    L = Len(s)
    msg = L & vbCrLf
    For i = 1 To L
        msg = msg & i & "    " & AscW(Mid(s, i, 1)) & vbCrLf
    Next i
    WhatsIn = msg
End Function

The function tells us exactly what a cell contains. It gives:

  1. the number of characters
  2. for each character, the unicode value

    Here is an example:

enter image description here

We know how many characters cell C2 contains and we know the ASCII code for each character.

User Defined Functions (UDFs) are very easy to install and use:

  1. ALT-F11 brings up the VBE window
  2. ALT-I ALT-M opens a fresh module
  3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the UDF:

  1. bring up the VBE window as above
  2. clear the code out
  3. close the VBE window

To use the UDF from Excel:

=WhatsIn(A1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

and for specifics on UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

Macros must be enabled for this to work!

Once we know the ASCII number, run a macro like:

Sub KleanUp()
    Cells.Replace ChrW(166), ""
End Sub

where we would replace the 166 with the actual number.

Gary's Student

Posted 2018-01-04T20:18:30.613

Reputation: 15 540

Thanks for such details! I've got some experience with formulas and coding, so hopefully I can make this work. Let you know! Thanks again. – Adam White – 2018-01-04T23:45:02.537

@AdamWhite ...............Good Luck!....................... – Gary's Student – 2018-01-04T23:45:58.777

This is fantastic. You always seem to cut right to the crux of the problem. And I'm dying to know what the evil, mysterious character is. :-) – Bandersnatch – 2018-01-05T02:50:35.497

@Bandersnatch ..................me too..................the truth is out there somewhere........ – Gary's Student – 2018-01-05T02:58:48.703