Add a space before the % in the graphs
Solved
moi35534
-
moi35534 -
moi35534 -
Hello,
Does anyone know how we could program an Excel macro to add a space in front of the percent sign in the data labels?
Thanks!
Configuration: Windows XP / Internet Explorer 7.0
Does anyone know how we could program an Excel macro to add a space in front of the percent sign in the data labels?
Thanks!
Configuration: Windows XP / Internet Explorer 7.0
3 answers
-
Hello,
A macro may not be necessary.
We can choose a custom format for the data labels.
For example: 0,00" "%% if 2 decimals are desired. Be careful to include the space inside the quotes. -
Hello, without a macro, it would be enough to do it in the spreadsheet, with a macro something like this: Public Sub EspaceDevantEtiquette() Dim nbpts As Long, nupt As Long Dim etiq As String With ChartObjects(1).Chart.SeriesCollection(1) nbpts = .Points.Count For nupt = 1 To nbpts etiq = .Points(nupt).DataLabel.Characters.Text etiq = " " & etiq .Points(nupt).DataLabel.Characters.Text = etiq Next nupt End With End Sub. Good luck.
-
Oh yeah!
Thanks ccm81, I’ve slightly modified your macro since the space had to be before the % (which was at the end of the label text, in my case). The final code is:
Sub EspaceDevantPourcent()
Dim nbpts As Long, nupt As Long
Dim etiq As String
With ActiveChart.SeriesCollection(1)
nbpts = .Points.Count
For nupt = 1 To nbpts
etiq = Left(.Points(nupt).DataLabel.Characters.Text, .Points(nupt).DataLabel.Characters.Count - 1)
etiq = etiq & " %"
.Points(nupt).DataLabel.Characters.Text = etiq
Next nupt
End With
End Sub
@tontong : I’m not sure if it’s possible, since Excel (2003) generates the percentages in the charts from the data tables themselves (numerical, in my case, and not already as percentages).