Add a space before the % in the graphs

Solved
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

3 answers

tontong Posted messages 2575 Registration date   Status Member Last intervention   1 064
 
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.
0
ccm81 Posted messages 11033 Status Member 2 434
 
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.
0
moi35534
 
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).
0
tontong Posted messages 2575 Registration date   Status Member Last intervention   1 064
 
I'm not sure that's possible
But I am. The generated percentages remain data labels, and it is possible to choose the format of these labels.
0
ccm81 Posted messages 11033 Status Member 2 434
 
@tontong
greetings
he asked for a macro, so ...

@moi35534
if tontong says something about the charts, there’s a good chance it’s correct.....
0
moi35534
 
Haha, so how is that possible?
0