Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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. |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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! |
#6
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Linking two IF statements together | Excel Discussion (Misc queries) | |||
how do i superscript part of a cell in MS Excel? | Excel Discussion (Misc queries) | |||
how do i superscript part of a cell in MS Excel? | Excel Discussion (Misc queries) | |||
Nested IF statements | Excel Worksheet Functions | |||
Formula window displays correct answer while cell displays incorre | Excel Worksheet Functions |