Catching a superscript in a .csv file header?

jxb

Board Regular
Joined
Apr 19, 2007
Messages
172
Office Version
  1. 2010
Platform
  1. Windows
I have a macro to post process data (in a csv format) and import it in a 1/3 party tool. Works fine

I have however just got an issue because the data header contains a (string) description a2/b in that the 2 is a (real) superscript (in the csv file) but my macro search for a2/b i.e. no superscript to do something with the column. This was the original format I worked with! Having done some “debugging” I found that the macro seems to recognise the format as a?/b where ? appears as a black losange. What is this format?

More importantly now that I know I could end up with this issue is there a way of catching this format “on the fly”. I could search on both?

Granted that I could have a small Check function to replace the culprit string but I still need to know how to find it

Thanks
Regards
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I found that the macro seems to recognise the format as a?/b where ? appears as a black losange. What is this format?
It isn't a format. It's just displayed like that. The VBE cannot handle special characters like ² so these are displayed as a question mark ?

The approach is dependent on the binary file format, since a .csv or .txt file can have different appearances on disk. If the file is "pure" ANSI each character consists of one byte, in UTF-8 or UTF-16 (both big endian & little endian) special characters are represented by two bytes. You could try replacing the special character within Excel after importing. Perhaps it would be better to read the contents of the file beforehand, replace all occurences of ² with 2 and write it back again.

_ file format _ : ² character
Rich (BB code):
ANSI      : 178
UTF-8     : 194 & 178
UTF-16 LE : 178 & 0
UTF-16 BE :   0 & 178
 
Upvote 0
Solution
It isn't a format. It's just displayed like that. The VBE cannot handle special characters like ² so these are displayed as a question mark ?

The approach is dependent on the binary file format, since a .csv or .txt file can have different appearances on disk. If the file is "pure" ANSI each character consists of one byte, in UTF-8 or UTF-16 (both big endian & little endian) special characters are represented by two bytes. You could try replacing the special character within Excel after importing. Perhaps it would be better to read the contents of the file beforehand, replace all occurences of ² with 2 and write it back again.

_ file format _ : ² character
Rich (BB code):
ANSI      : 178
UTF-8     : 194 & 178
UTF-16 LE : 178 & 0
UTF-16 BE :   0 & 178
Thanks for the explanation. I had a look and indeed changing beforehand the "faulty" header appear to be the easiest apprpoach I already have a macro to do a couple things and a 1st rough test using
VBA Code:
Selection.Replace
seems to do the job. I just need to add a couple of lines in my existing loop

Thanks again
 
Upvote 0
You are welcome and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,462
Members
448,965
Latest member
grijken

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