Forum Discussion
taufiq6121
Jun 09, 2022Copper Contributor
How to type superscript in Excel macro?
Hello,
I am new to writing Excel macros and really appreciate your help.
I am trying to write a macro to process all worksheets in an Excel file and import the data into one single worksheet. However, one of my worksheet titles is written with superscript (px²). And when I ran the macro, it will be Runtime Error 9: Subscript Out of Range.
When I checked the macro script, the px² was changed to px2 which I suspect is the reason. However, I cannot type px² in the macro script. Therefore, what can I do?
Changing the worksheet title will take some time because I have many Excel files exported from another software.
I am sorry if the question is hard to understand. I am happy to write it clearly.
Dear HansVogelaar
Thank you very much for your suggestion regarding the language. I managed to get the solution.
By changing the Language for non-Unicode Programs to English (United States) in the Control Panel, the superscript and other symbols can be written in the VBA
My default was Japanese (Japan) and even English (United Kingdom) was unsuccessful.
Here's also the link that I referred to
I really appreciate your help by responding to my question.
Please have a good day.
The Visual Basic Editor should be able to handle ²:
Screenshot:
Code:
Sub Test() Dim wsh As Worksheet Set wsh = Worksheets("px²") End Sub
- taufiq6121Copper Contributor
Dear HansVogelaar
Thank you for your reply. However, I still cannot insert the superscript even by pasting from your code. Please find the screenshot below.
When I tried copying the Superscript Two symbol into the VBA, the Superscript Two symbol changed to a question mark.
That's a pity - it might have to do with your language settings, but I'm afraid I don't have a solution for you, except renaming the sheets.