EXCEL如何判断所有单元格有数据后自动执行上标! 我原来用的宏代码必须

2024-11-23 02:21:50
推荐回答(2个)
回答1:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Dim c As Range, i As Long

For Each c In ActiveSheet.UsedRange

If c Like "*+*" Then

i = InStr(c, "+")

c.Characters(i, Len(c) - i + 1).Font.Superscript = True

End If

Next c

End Sub

回答2:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
If Target <> "" And Target Like "*+*" Then
i = InStr(Target, "+")
Target.Characters(i, Len(Target) - i + 1).Font.Superscript = True
End If
End Sub
用Worksheet_Change事件而不用Workbook_SheetChange事件。也不必循环,直接对发生变化的单元格进行操作。