Superscript only a portion of a data label, using VBA

coreyalderin

New Member
Joined
Jun 9, 2011
Messages
19
Is it possible to superscript only a portion of a chart's data label, using VBA?

In the older version of Excel I was able to use this:

With Selection.Characters(Start:=Length2 + 1, Length:=Length1).Font
.Superscript = True

but since converting to the new version of Excel, that code no longer works. I tried recording the steps, but the recorded program superscripts the whole data label.
Thank you
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try
Code:
Selection.Characters(Start:=Length2 + 1, Length:=Length1).Font.Superscript = True
I don't know what the variables Length2 and Length1 stand for, but the line
works fine for me using absolute values in Excel 2010.
 
Upvote 0
Could you provide an example of what the strings you want to change look like and what the values for Length1 and Length2 are?
 
Upvote 0
What I am trying to do:
  • User selects a label in a chart that is embedded in a worksheet. For example, in a bar graph the label indicating tha value of the graph.
  • A pop-up window appears asking the user to enter text that they want included on the label
  • That text is then included with the value that is already there, as a superscript.
With the below code, the entire data label is formatted as a superscript.


Code:

Private Sub EmbChart_Select(ByVal ElementID As Long, _
ByVal Arg1 As Long, ByVal Arg2 As Long)

If Arg2 > 0 Then
sScript = InputBox("Type in the superscript exactly how you want it", "Superscript", "Enter superscript here")

If sScript <> "" Then

Length1 = Len(sScript)


Text = ActiveChart.SeriesCollection(Arg1).Points(Arg2).DataLabel.Text
Length2 = Len(Text)

Selection.Characters.Text = Text & sScript

Selection.Characters(Start:=Length2 + 1, Length:=Length1).Font.Superscript = True
ActiveSheet.ChartObjects(Number).Activate
End If
End If



End Sub
 
Upvote 0
That's strange. I created a chart, selected a data label and ran your code. It executed perfectly and only the text I entered was formatted as superstring.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top