在 VBA 中编写下标值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11114192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Writing Subscript Values In VBA
提问by james
回答by Craig T
Try the following:
请尝试以下操作:
Range("T4").Value = "Rule 13s voilation"
Range("T4").Characters(Start:=7, Length:=2).Font.Subscript = True
I am not sure how this will work for you with dynamic string lengths.
我不确定这对动态字符串长度将如何工作。
回答by Jean-Fran?ois Corbett
Try doing it manually while recording a macro, and then looking at the resulting code. That will give you your answer.
尝试在录制宏时手动执行此操作,然后查看生成的代码。那会给你答案。
Here's a cleaned up answer:
这是一个清理过的答案:
With Range("T4")
.Value = "Rule 13s voilation" ' (sic)
.Characters(Start:=7, Length:=2).Font.Subscript = True
End With
回答by webdjer
I use this function to concatenate 2 cells into one. the first one is a text, the second one is a serie of reference to comments
我使用此函数将 2 个单元格连接成一个。第一个是文本,第二个是一系列参考评论
Sub setRefWithRemark()
Dim aCellRef, aCellRem, aCelTarget As Range
Dim aRow As Range
For Each aRow In Range("rgtensileRefWithRemark").Rows
Set aCellRef = aRow.Cells(1, 1)
Set aCellRem = aRow.Cells(1, 12)
Set aCellTarget = aRow.Cells(1, 17)
If aCellRef.Text <> "" Then
With aCellTarget
.value = aCellRef.Text & cTextSeparator & aCellRem.Text ' (sic)
.Characters(Start:=Len(aCellRef.Text) + 2, Length:=Len(aCellRem.Text)).Font.Superscript = True
End With
End If
Next
End Sub