Add superscript to a char in a cell with a formula

BennyBatt

New Member
Joined
Sep 11, 2023
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hi, everybody.
Probably there is an easy solution, or maybe there no solution as well, to this problem.

The scenario is simple: I have a cell (well, many others with the same issue, but this doesn't matter) in a sheet with a formula that create a text in different ways dependoing on other cells content.
I'd like to format the inner text with a character superscript, but because of the formula, my simple code doesn't change nothing in the text.
The cell has a text format.
This the code:
VBA Code:
Set area = Cells(80, 1)
'area.NumberFormat = "@"
area.Characters(Start:=7, Length:=1).Font.Superscript = True
Inside the cell there is a formula like this:
Excel Formula:
="[" &  INDICE(Tab_lingue;Lingua;100) &"]"
and the final text showed to the user is "[BTU/f3]".
I'd like to put the "3" in the text to superscript.
Is it possible?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
As I haven't receiced any answers, I understood the second eventuality assumed at the beginning of my question was correct: there is not a solution.
So, I follow a different plan, not exactly a trick, but a way to make advance. I report this in case someone would need it.

In practical I moved the formula from the cell to a code sub, where I prepare the text to write in the above mentioned cell, applying the superscript.
This is the code sub:

VBA Code:
Sub superscript(iCol As Integer, iColUM As Integer, nChar As Integer)
dim sArea as string
'iCol       --> column of the destination cell
'iColUM --> column of the cell with data to handle
iLingua = Range("Lingua").Value
'control that the column of the cell is inside the correct range
If iCol < 1 Or iCol > 20 Or iColUM < 1 Or iColUM > 20 Then Exit Sub
'control that the cell with data to manage contains a value
If Cells(71 + iLingua, 156 + iColUM) = "" Then Exit Sub
'prepare the text
sArea = "[" & Cells(71 + iLingua, 156 + iColUM) & "]"
'check for the avaiable superscript char's position
If Len(sArea) < nChar Or nChar < 1 Then Exit Sub
Cells(10, 2 + iCol) = sArea
'add the superscript
Cells(10, 2 + iCol).Characters(Start:=nChar, Length:=1).Font.Superscript = True
End Sub

Example of calling:
VBA Code:
Call superscript(3, 2, 3)
Note that the code handles only a char for superscript.
It goes without saying that the code can be improved, and/or transformed into a function.
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,218
Members
449,091
Latest member
jeremy_bp001

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