I have a string:Range("T4").Value = "Rule 13s voilation"
I want to write 13s
like 13s
i.e 3
and s
are a subscript of 1
.
Please suggest on how should I go about it in vba
Subscript out of range is an error we encounter in VBA when we try to reference something or a variable that does not exist in a code. For example, suppose we do not have a variable named x. Then, if we use the MsgBox function on x, we will encounter a “Subscript out of range” error.
If you want Excel VBA to perform some actions, you can use a sub. Place a sub into a module (In the Visual Basic Editor, click Insert, Module). For example, the sub with name Area.
Explanation: the 'subscript out of range' error pops up because there's no 4th worksheet. To fix this error, change the 4 to a 1, 2 or 3 (or insert a new worksheet by clicking the plus sign).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With