'You can make the first character in the A1 cell subscript like this
Worksheets("Sheet1").Range("A1").Characters(0, 1).Font.Subscript = True
扩展示例
Sub SubscriptWithRegex()
'Create a new regex object, import reference from
'Tools > References > Microsoft VBScript Regular Expressions 5.5
Set regex = New RegExp
'Define the pattern, use regexr.com to test and write regex
'For this example we will subscript all L characters after a V
regex.Pattern = "V(L+)"
'if TRUE, find all matches, if FALSE find only the first match
regex.Global = True
'Iterate trough cells in Sheet1 range A1:A6
For Each cell In Worksheets("Sheet1").Range("A1:A6")
'Search for the pattern
Set matches = regex.Execute(cell.Value)
'Iterate trough the matches
For Each Match In matches
'Make characters subscript
'We need to shift the match to left by 2 to skip the V character
'and we need to subtract that single V from the total length
cell.Characters(Match.FirstIndex + 2, Match.Length - 1).Font.Subscript = True
Next
Next
End Sub
为此,您可以编写一个宏,然后从开发人员选项卡中运行它。
有关如何运行宏或启用开发人员工具的更多信息,请参阅支持页面
扩展示例
运行宏之前和之后
参考
Excel VBA 参考
字体对象 (Excel)
字符对象 (Excel)