Excel VBA Font.Superscript code does not work

2019-09-17 03:10发布

This excel code does not work. Why? Indeed I can not make work any superscript code. I use Excel 2007

note: intRow and intColumn are integers which determine the row and column.

Cells(intRow, intColumn).Characters(Start:=Len(Cells(intRow, intColumn).Value), Length:=1).Font.Superscript = True

2条回答
可以哭但决不认输i
2楼-- · 2019-09-17 03:50

I found the problem. It is the format of the cell. It must be text.

Adding that line before the superscript line solved the problem:

Cells(intRow, intColumn).NumberFormat = "@"

Thanks.

查看更多
Bombasti
3楼-- · 2019-09-17 03:59

You need to fully qualify all your cells. This works:

Option Explicit

Public Sub test()
    SuperscriptLastLetter 1, 1
End Sub

Public Sub SuperscriptLastLetter(ByVal lngRow As Long, ByVal lngCol As Long)

    With ActiveSheet.Cells(lngRow, lngCol)

        .Characters(Start:=Len(.Value), Length:=1).Font.Superscript = True

    End With

End Sub

enter image description here

查看更多
登录 后发表回答