在我正在使用的VBA excel宏中,我有以下代码:
For k = MinDeg To MaxDeg
OutputStr = Trim(OutputStr & "a" & Str(k) & " = " & _
Str(MyCoe) & " ± " & _
Str(MyErr) & Chr(10))
Next k
Where" MyCoe"和#34; MyErr"给出数字," minDeg"和" MaxDeg"是整数。
我的问题是:
我如何制作" Str(k)"在outputstr中显示为下标文本?
答案 0 :(得分:1)
答案 1 :(得分:0)
首先,我将这个简单的mod运行到您的代码中:
Sub WhatEverr()
mindeg = 10
maxdeg = 13
mycoe = 3
myerr = 5
For k = mindeg To maxdeg
outputstr = Trim(outputstr & "a" & Str(k) & " = " & _
Str(mycoe) & " ± " & _
Str(myerr) & Chr(10))
Next k
Range("A1").Value = outputstr
End Sub
在 A1 :
中获取此信息然后我跑:
Sub formatcell()
Dim i As Long, L As Long, rng As Range
Dim s As String
Set rng = Range("A1")
s = rng.Value
L = Len(s)
For i = 1 To L
ch = Mid(s, i, 1)
If ch = "a" Then
rng.Characters(Start:=i + 2, Length:=2).Font.Subscript = True
End If
Next i
End Sub
要应用格式:
在Excel中,这种类型的字符格式是Range
对象的属性。您不像在HTML中那样将其构建到字符串中。