How to get a square character (²) to display in a string

I am trying to get ² to display in a row. As an example, my output should be inside the ActiveX text box and should read R² = 50 .

I tried the following two statements:

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

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

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

also displays a 0 .

+4
source share
3 answers

Not sure which text box you are linking to. However, I'm not sure if you can do this in a text box in a custom form.

The text box on the 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 the same for excel cell

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

If this is not what you need, you need to provide additional information in your question.

EDIT: posted this after comment sorry

+3
source

No need too complicated. If all you need is ², then use the Unicode representation.

http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

(I assume you got ² to appear in your question.)

+1
source

I create equations with random numbers in VBA and for square x in x ^ 2.

I read every square (or text) text in a line.

Then I read each character in the line one at a time and mark the location of ^ ("hats") in each.

It is said that the hats were in positions 4, 8 and 12.

Then I “cut out” the first hat - the position of the superscript is now 4, the position of the remaining hats is now 7 and 11. I chop off the second hat, the character at the top index is now 7, and the hat has moved to 10. I chop off the last hat. The top character is now at position 10.

Now I select each character in turn and change the font to superscript.

That way, I can populate the whole table with algebra using ^, and then call the procedure to remove it.

For large degrees, such as x for 23, I build x ^ 2 ^ 3, and this procedure is performed.

0
source

Source: https://habr.com/ru/post/1442220/


All Articles