Displays statements in Subcript or superscript using "If" formula

A

Air Lancer

Hi all,

how do i create a "if" statement that displays words in subcript or
superscript?

e.g. = if (A1>A2, "Pa > Pb", "Pb > Pa"), where the "a" and "b" should be
displayed as subscripts to "P".

thk.
 
B

Bernie Deitrick

Air,

You have to do that using VBA code.

For example, copy the code below, right-click on the sheet tab where you want that IF function,
select "View Code", and paste the code into the window that appears.

Change the "A3" to reflect the cell address of the cell where you wanted that formula.

If you have no other formulas, you might need to use the change event instead.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Calculate()
Application.EnableEvents = False
With Range("A3")
If Range("A1").Value > Range("A2").Value Then
.Value = "Pa > Pb"
ElseIf Range("A1").Value < Range("A2").Value Then
.Value = "Pb > Pa"
Else
.Value = "Pa = Pb"
End If
.Characters(Start:=2, Length:=1).Font.Subscript = True
.Characters(Start:=7, Length:=1).Font.Subscript = True
End With
Application.EnableEvents = True
End Sub
 
A

Air Lancer

it works. THX!

Bernie Deitrick said:
Air,

You have to do that using VBA code.

For example, copy the code below, right-click on the sheet tab where you want that IF function,
select "View Code", and paste the code into the window that appears.

Change the "A3" to reflect the cell address of the cell where you wanted that formula.

If you have no other formulas, you might need to use the change event instead.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Calculate()
Application.EnableEvents = False
With Range("A3")
If Range("A1").Value > Range("A2").Value Then
.Value = "Pa > Pb"
ElseIf Range("A1").Value < Range("A2").Value Then
.Value = "Pb > Pa"
Else
.Value = "Pa = Pb"
End If
.Characters(Start:=2, Length:=1).Font.Subscript = True
.Characters(Start:=7, Length:=1).Font.Subscript = True
End With
Application.EnableEvents = True
End Sub
 
B

Bernie Deitrick

Air,

Glad to hear that you were actually able to follow my poorly-written instructions.... ;-)

Bernie
MS Excel MVP
 
J

jahoobob

As far as I know, it can't be done because Excel only allows formatting
at the cell level, not the characete level like Word.
 
Top