您现在的位置是:首页 > Excel技巧>excel 设置单元格设定字符为上标

excel怎么设置单元格为上标-excel 设置单元格设定字符为上标

发布于2022-04-150人已围观

在工作生活中,因为有的行业的特殊性,有的单元格的部分数据会出现上标/下标。

在数据录入过程中,我们可以设定单元格格式来设置为上标或者下标。


如果有大量的单元格中存在某个字符需要设置为上标,我们该如何批量设置?

这里通过一段vba自定义函数,批量设定选中的单元格的某个字符作为上标,这里以“*”为例

excel怎么设置单元格为上标


Sub 标上上标()
'    先选择单元格(可以为多个),再运行此宏
    Dim TRan As Range, FirstAddress As String, FindStr As String, i, j, k, l
    FindStr = "*" '标上上标的字符串
    With Selection
        Set TRan = .Find(FindStr, LookIn:=xlValues)
        If Not TRan Is Nothing Then
            FirstAddress = TRan.Address
            Do
                i = (Len(TRan.Value) - Len(WorksheetFunction.Substitute(TRan.Value, FindStr, ""))) / Len(FindStr)
                k = 1
                For j = 1 To i
                    l = WorksheetFunction.Find(FindStr, TRan.Value, k)
                    TRan.Characters(Start:=l, Length:=Len(FindStr)).Font.Superscript = True
                    k = l + Len(FindStr)
                Next
                Set TRan = .FindNext(TRan)
            Loop While Not TRan Is Nothing And TRan.Address <> FirstAddress
        End If
    End With
End Sub


选中需要设置的单元格,运行代码:

excel怎么设置单元格为上标


参考至:excel吧


相关文章

文章评论

表情

共0条评论
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

标签云

站长特荐