UDF to Convert Numbers in String to Subscript

Anonymous
2023-08-05T00:43:20+00:00

Running into challenges in developing a UDF that evaluates one string in a cell and converts all the numbers in the string to subscript.

Example string to convert: A0G2P14C0P3M6G0A0

This not working. Thanks.

Public Function NumToSub(R As Range) As String

Dim i As Integer

NumToSub = ""

With ActiveSheet.R 

    For i = 1 To .Characters.Count 

        Set ch = .Characters(i, 1) 

            If IsNumeric(ch.Text) Then 

                ch.Font.Subscript = True 

                NumToSub = NumToSub & ch.Text 

            End If 

    Next i 

End With 

End Function

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Anonymous
    2023-08-05T04:26:59+00:00

    Hi,

    What would you want your example to return, can you show us?

    Thanks,

    0 comments No comments
  2. Andreas Killer 144K Reputation points Volunteer Moderator
    2023-08-05T11:01:04+00:00

    Function JustNumbers(ByVal What As String) As String
    'Return only numbers from What (by Rick Rothstein)
    Dim i As Long, j As Long, Digit As String
    For i = 1 To Len(What)
    Digit = Mid$(What, i, 1)
    If Digit Like "#" Then
    j = j + 1
    Mid$(What, j, 1) = Digit
    End If
    Next
    JustNumbers = Left$(What, j)
    End Function

    0 comments No comments
  3. Anonymous
    2023-08-05T23:33:01+00:00

    https://b23.tv/adEMzxQ How about this way?

    0 comments No comments
  4. Andreas Killer 144K Reputation points Volunteer Moderator
    2023-08-06T08:25:41+00:00

    【批量数字下标-batch number subscript-哔哩哔哩】 How about this way?

    I'm sorry but your post is not helpful in this forum.

    The reason for this is the language, all participants here speak English or can use a translator to translate English text into their language.

    Your native language is probably Chinese, so nobody will probably understand your video. Me neither, because the OP asked for a VBA solution, not how to do anything with copy and paste.

    Please keep in mind that your solutions here are only helpful if they are written in English. Nobody can read what is written in Chinese to the left and right of "batch number subscript" above.

    There are also forums in your language, it might make more sense to get more involved in these forums.
    https://answers.microsoft.com/zh-hans/msoffice/forum/msoffice_excel

    https://answers.microsoft.com/zh-hant/msoffice/forum/msoffice_excel

    Andreas.

    0 comments No comments
  5. Anonymous
    2023-08-06T10:19:36+00:00

    Sorry I have deleted Chinsese.

    I am here just for fun.

    If not helpful,please delete it.

    0 comments No comments