ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Displays statements in Subcript or superscript using "If" formula (https://www.excelbanter.com/excel-discussion-misc-queries/49206-displays-statements-subcript-superscript-using-%22if%22-formula.html)

Air Lancer

Displays statements in Subcript or superscript using "If" formula
 
Hi all,

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

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

thk.

Dave Peterson

Excel doesn't support this kind of formatting for formulas.

Air Lancer wrote:

Hi all,

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

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

thk.


--

Dave Peterson

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



"Air Lancer" wrote in message
...
Hi all,

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

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

thk.




Air Lancer

it works. THX!

"Bernie Deitrick" wrote:

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



"Air Lancer" wrote in message
...
Hi all,

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

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

thk.





Bernie Deitrick

Air,

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

Bernie
MS Excel MVP


"Air Lancer" wrote
it works. THX!




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.
Air Lancer Wrote:
Hi all,

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

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

thk.



--
jahoobob


All times are GMT +1. The time now is 08:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com