Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a variable with subscripts 1

Status
Not open for further replies.

Stoffel24

Technical User
Apr 4, 2002
121
ZA
Hello
I would like to be able to create a variable with subscripts in it (Eg CO2 where the 2 is subscript).

My code is
'...part of a loop
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = Sheets(1).Cells(2, 3).Value & " (" & Cmpd & ")"

This will give me Eg Program 34 CO2 where Cmpd = CO2. I want the 2 to be subscript. If I could change the variable Cmpd such that it has subscripts that would really help.

Any ideas?
 
Stoffel24,

There is no such animal as a variable that contains subscripts. Subscripts are a function of the formatting that is applied to text displayed on the screen. You can readily achieve the effect you want, however, with Excel's object model.

Try the following code:


With ActiveChart
.HasTitle = True
.ChartTitle.Text = Sheets(1).Cells(2, 3).Value & " (" & Cmpd & ")"
.ChartTitle.Characters(Position, 1).Font.Subscript = True
End With

You will need to calculate the value of Position. In this case, it might be
Code:
Len(.ChartTitle.Text) - 1

Hope this helps.
M. Smith
 
That did help. I actually did what you suggested already but it is nice to know that subscripts are not a possibility in variables in VB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top