I need to make this a subscript in the output of Excel. In essence, I want all of the output's numbers to be subscripted.

This code, which I tested, is a section of a lengthy IF "loop."

```B2=2

=(B2="","","C"&B2) = C2
```

where I want an output that looks like this: C 2 (it would also be good if you could get a real C subscript there instead of C 2 when creating the inquiry).

Because this is a general and changeable output where things change with other elements to produce new result, the formatting did not work.

C2O2H, C6H6, C4ON, C4H6N4, C5H8S2, and so forth.

I need a formula that accomplishes this for me, or VBA, rather than manually formatting output because you can only do it once you've finished creating the combination, then you have to start again the following time.

Apr 3, 2023 in Others 438 views

## 1 answer to this question.

Convert Digits To Subscript (H₂SO₄)

Excel Formula Improvement (Edit)

• A huge improvement was suggested by David Leal in the comments:
```=LET(d,A1,
ds,MID(d,SEQUENCE(LEN(d)),1),
TEXTJOIN("",,IFERROR(UNICHAR(832&ds),ds)))
```
• The LAMBDA function would be something like this:
```=LAMBDA(Compound,
LET(ds,MID(Compound,SEQUENCE(LEN(Compound)),1),
TEXTJOIN("",,IFERROR(UNICHAR(832&ds),ds))))
```

See in the continuation how to use it.

Excel Formula (Function)

```=LET(d,A1,
ds,MID(d,SEQUENCE(LEN(d)),1),
s,MOD(SEQUENCE(10),10),
TEXTJOIN("",,IF(ISNUMBER(MATCH(--ds,s,0)),UNICHAR(832&ds),ds)))
```
• You could create a LAMBDA function:
```=LAMBDA(Compound,LET(
ds,MID(Compound,SEQUENCE(LEN(Compound)),1),
s,MOD(SEQUENCE(10),10),
TEXTJOIN("",,IF(ISNUMBER(MATCH(--ds,s,0)),UNICHAR(832&ds),ds))))
```
• Using Ribbon->Formulas->Defined Names->Define Name, you need to come up with a name (e.g. Chem, Compound, SubComp...) and enter it into the Name: box and enter the formula into the Refers to: box. Now you can use the function e.g. simply with

```=Chem(A1)
=Chem("H2SO4")
```
• Note that you can use the function in the entire workbook.

VBA

```Function Chemis(ByVal Compound As String) As String

Dim n As Long, Char As String, Comp As String

For n = 1 To Len(Compound)
Char = Mid(Compound, n, 1)
If Char Like "#" Then
Comp = Comp & ChrW(832 & Char)
Else
Comp = Comp & Char
End If
Next n

Chemis = Comp

End Function```
• 63,720 points

## How to get the URL of the current tab in Google Chrome?

Its so simple.... If you want to ...READ MORE

## How to search a file with a particular extension and a particulat string in its name?

You can easily find the file using ...READ MORE

## Calculate Birthdate from an age using y,m,d in Excel

Hi To Calculate the date, we can ...READ MORE

## Convert Rows to Columns with values in Excel using custom format

1 I having a Excel sheet with 1 ...READ MORE

## IF - ELSE IF - ELSE Structure in Excel

In this case, you can use nested ...READ MORE