vbaexcelexcel-2007

How to get the squared symbol (²) to display in a string


I'm trying to get ² to show in a string. As an example my output should be inside a ActiveX Textbox and should read R² = 50.

I've tried the following two statements:

Selection.Characters.Text = "R&ChrW(&HB2)&" = " & variable

but this displays a 0 as the output in the Textbox. And this:

Selection.Characters.Text = "R² = " & variable

also displays a 0.


Solution

  • Not sure what kind of text box you are refering to. However, I'm not sure if you can do this in a text box on a user form.

    A text box on a sheet you can though.

    Sheets("Sheet1").Shapes("TextBox 1").TextFrame2.TextRange.Text = "R2=" & variable
    Sheets("Sheet1").Shapes("TextBox 1").TextFrame2.TextRange.Characters(2, 1).Font.Superscript = msoTrue
    

    And same thing for an excel cell

    Sheets("Sheet1").Range("A1").Characters(2, 1).Font.Superscript = True
    

    If this isn't what you're after you will need to provide more information in your question.

    EDIT: posted this after the comment sorry