Mushahid Hussain
Mushahid Hussain

Reputation: 4055

Writing Subscript Values In VBA

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

Upvotes: 5

Views: 17191

Answers (3)

webdjer
webdjer

Reputation: 11

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

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

Upvotes: 1

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

Upvotes: 7

Craig T
Craig T

Reputation: 2742

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.

Upvotes: 11

Related Questions