how to get subscript into formulas text string

use*_*617 1 excel excel-formula

in excel I need to get this to be a subscript in the output.

Basically I want all the numbers in the output to be subscripted

I have tried this code, and it is part of a large IF "loop"


B2=2

=(B2="","","C"&B2) = C2
Run Code Online (Sandbox Code Playgroud)

where I desire an output like this C_2 (any help to get an actual C subscript her in the question box and not C_2, when making the question, would also be helpful)

the formatting did not work because this is a generic and changing out put where these change with other elements giving different output like

C2O2H, C6H6, C4ON ,C4H6N4 C5H8S2 Etc.

and you can only manually format output once done making the combination, then the next time you need to start over, instead of formatting I need a formula that does this for me, or VBA.

Please help!

VBa*_*008 6

将数字转换为下标 (H\xe2\x82\x82SO\xe2\x82\x84)

\n

Excel 公式改进(编辑)

\n
    \n
  • David Leal 在评论中提出了一个巨大的改进:
  • \n
\n
=LET(d,A1,\n    ds,MID(d,SEQUENCE(LEN(d)),1),\nTEXTJOIN("",,IFERROR(UNICHAR(832&ds),ds)))\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  • LAMBDA函数将是这样的:
  • \n
\n
=LAMBDA(Compound,\n    LET(ds,MID(Compound,SEQUENCE(LEN(Compound)),1),\nTEXTJOIN("",,IFERROR(UNICHAR(832&ds),ds))))\n
Run Code Online (Sandbox Code Playgroud)\n

请参阅后续内容如何使用它。

\n

Excel 公式(函数)

\n
=LET(d,A1,\n    ds,MID(d,SEQUENCE(LEN(d)),1),\n    s,MOD(SEQUENCE(10),10),\nTEXTJOIN("",,IF(ISNUMBER(MATCH(--ds,s,0)),UNICHAR(832&ds),ds)))\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  • 您可以创建一个LAMBDA函数:
  • \n
\n
=LAMBDA(Compound,LET(\n    ds,MID(Compound,SEQUENCE(LEN(Compound)),1),\n    s,MOD(SEQUENCE(10),10),\nTEXTJOIN("",,IF(ISNUMBER(MATCH(--ds,s,0)),UNICHAR(832&ds),ds))))\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  • 使用 时Ribbon->Formulas->Defined Names->Define Name,您需要想出一个名称(例如Chem,,...)并将其输入到框中,然后Compound将公式输入到框中。现在您可以使用该功能,例如简单地使用SubCompName:Refers to:

    \n
    =Chem(A1)\n=Chem("H2SO4")\n
    Run Code Online (Sandbox Code Playgroud)\n
  • \n
  • 请注意,您可以在整个工作簿中使用该函数。

    \n
  • \n
\n

编程语言

\n
=LET(d,A1,\n    ds,MID(d,SEQUENCE(LEN(d)),1),\nTEXTJOIN("",,IFERROR(UNICHAR(832&ds),ds)))\n
Run Code Online (Sandbox Code Playgroud)\n

  • 有趣的是,我不知道这个 UNICHAR 技巧来创建下标,也许我错过了一些东西,但是这个怎么样?`=LET(d,A1,ds,MID(d,SEQUENCE(LEN(d)),1), TEXTJOIN("",,IFERROR(UNICHAR(832&ds),ds)))` (3认同)
  • @DavidLeal 太棒了。如果这还不算改进,那么什么是:缩短了 55 个字符,并且当复制到 1M 行时,Excel 在 22 秒后恢复,而我的解决方案需要 25 秒。我不知道,但我认为你应该发布它,因为仅仅在我的回答中归功于你感觉不正确(足够)。我不介意,你当然可以做类似*“基于这个想法......我想出了......改进......*”之类的事情。显然,我对365之前的所有技巧和想法缺乏了解。我是VBA人员,对吧? (2认同)
  • 谢谢,但没关系,我不能单独想到你的想法,当它是相同的想法时,我感觉不好发布新答案,只是比你的想法有所改进,但无论如何还是谢谢。如果您愿意,您可以更新您的答案并给予我信任,这就足够了 (2认同)
  • 然后我会把它合并起来,因为它不能浪费在评论中。 (2认同)