Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Erreur 91 - pb macro étiquette de données

3 réponses
Avatar
le-duch
Bonjour,

Je cherche à réaliser un graphique (nuage de points) avec la légende des couples de points (x;y) précisée. J'ai repéré une macro sur le support Microsoft mais elle bloque.
Cf. : http://support.microsoft.com/kb/213750/fr

Message : Erreur 91
Variable objet ou variable de bloc With non définie.
Le problème est sur la ligne : xVals = ActiveChart.SeriesCollection(1).Formula

Il faut que j'arrive à générer ce graphe dès que possible pour une présentation client.
J'avais la même dans un autre fichier exwcel faite par un collègue (parti depuis) mais elle bloque aussi... :-(
Merci pour votre aide !
Bien cordialement.

Voici une copie de la macro :


Sub AttachLabelsToPoints()

'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String

' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False

'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula

'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop

'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).HasDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).DataLabel.Text = _
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter

End Sub

3 réponses

Avatar
h2so4
sans garantie,

peux-tu essayer avec les corrections ci-dessous ?


on 4/05/2011, le-duch supposed :


Sub AttachLabelsToPoints()

'Dimension variables.


Dim Ctr As Integer, xVals As String

' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False

'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula

'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop

'Attach a label to each data point in the chart.


For Ctr = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Ctr).HasDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Ctr).DataLabel.Text = _
Range(xVals).Cells(Ctr, 1).Offset(0, -1).Value
Next Ctr

End Sub



--
h2so4
ca PAN
pique DORA
.
Avatar
h2so4
h2so4 presented the following explanation :
j'ai essayé le code que tu as donné.

il fonctionne sans probleme chez moi.
il faut selectionner le graphique avant de lancer la macro

--
h2so4
ca PAN
pique DORA
.
Avatar
le-duch
h2so4 a écrit le 04/05/2011 à 22h24 :
h2so4 presented the following explanation :
j'ai essayé le code que tu as donné.

il fonctionne sans probleme chez moi.
il faut selectionner le graphique avant de lancer la macro

--
h2so4
ca PAN
pique DORA
.


Effectivement ! Une collègue l'a fait sur un fichier excel "propre" (nouveau) et ça fonctionne nickel.
Mystère de l'informatique (pour moi).
Quoi qu'il en soit, merci beaucoup pour ton aide.
Pour une 1ère fois à demander ce genre d'aide, je vois que ça marche bien.
Good !

Bonne journée.
Bien cordialement,