How to get subscript into formulas text string

0 votes

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 by Kithuzzz
• 38,020 points
628 views

1 answer to this question.

0 votes

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
answered Apr 3, 2023 by narikkadan
• 63,720 points

Related Questions In Others

0 votes
2 answers

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

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

answered Aug 12, 2020 in Others by Steve
• 200 points
3,521 views
0 votes
1 answer
0 votes
0 answers

how to list the contents of a asset into an event

May 29, 2019 in Others by anonymous
618 views
0 votes
0 answers

how to get another copy of my cert

Oct 1, 2019 in Others by Loletha
• 120 points
563 views
0 votes
1 answer

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

Hello, yes u can find your birthdate using ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
3,593 views
0 votes
1 answer

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

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

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,888 views
0 votes
0 answers

Convert Rows to Columns with values in Excel using custom format

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

Feb 17, 2022 in Others by Edureka
• 13,690 points
934 views
0 votes
1 answer

IF - ELSE IF - ELSE Structure in Excel

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

answered Feb 18, 2022 in Others by gaurav
• 23,260 points
3,472 views
0 votes
1 answer

How to get the JasperReports into Excel format with proper alignment

Remove at least one parameter: exporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN,Boolean.TRUE) Note that JRXlsExportParameter is deprecated the correct ...READ MORE

answered Sep 21, 2022 in Others by narikkadan
• 63,720 points
3,717 views
0 votes
1 answer

How to turn a string formula into a "real" formula?

Evaluate might suit: http://www.mrexcel.com/forum/showthread.php?t=62067 Function Eval(Ref As String) ...READ MORE

answered Jan 5, 2023 in Others by narikkadan
• 63,720 points
577 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP