prob pour affichage d'1 graph a partir d1 userform

  • Initiateur de la discussion nico64
  • Date de début
N

nico64

Guest
salut,
g un prob je n'arrive pas à afficher un graph a partir d'un userform qui determine la plage, la serie et la période à afficher.

voici le code de l'userform ou sinon le fichier a télécharger

merci d'avance

Option Explicit

Private Sub ComboBox1_Change()

End Sub

Private Sub CommandButton1_Click()
Dim X As Byte, i As Byte
Dim j As Integer, Debut As Integer, Fin As Integer
Dim Plage As Range, Plage2 As Range

If ListBox1.Value = '' Then Exit Sub
If ComboBox1.ListIndex = -1 Or ComboBox2.ListIndex = -1 Then Exit Sub

If ComboBox1.ListIndex > ComboBox2.ListIndex Then
MsgBox 'La date de fin ne peut pas etre antérieure à la date de début .'
Exit Sub
End If

Debut = ComboBox1.ListIndex + 2
Fin = ComboBox2.ListIndex + 2

Set Plage = Feuil1.Range('A' & Debut & ':A' & Fin)

Application.ScreenUpdating = False
Worksheets(1).ChartObjects('Graphique 1').Activate

For j = ActiveChart.SeriesCollection.Count To 1 Step -1
ActiveChart.SeriesCollection(j).Delete
Next j

For i = 0 To ListBox1.ListCount - 1 'boucle sur les éléments de la listbox

If ListBox1.Selected(i) = True Then
X = X + 1

ActiveChart.SeriesCollection.NewSeries
Set Plage2 = Feuil1.Range(Feuil1.Cells(Debut, i + 2).Address & ':' & Feuil1.Cells(Fin, i + 2).Address)

ActiveChart.SeriesCollection(X).Values = Plage2
If X = 1 Then ActiveChart.SeriesCollection(X).XValues = Plage
ActiveChart.SeriesCollection(X).Name = ListBox1.List(i) ' nom de la courbe
ActiveChart.SeriesCollection(X).Border.ColorIndex = i + 4
End If

Next i


Application.ScreenUpdating = True

End Sub

Private Sub Label1_Click()

End Sub

Private Sub UserForm_Initialize()
Dim X As Byte
Dim Y As Integer

For X = 2 To 6
ListBox1.AddItem Feuil1.Cells(1, X)
Next X

For Y = 2 To 366
ComboBox1.AddItem Format(Feuil1.Range('A' & Y), 'dd mmmm')
ComboBox2.AddItem Format(Feuil1.Range('A' & Y), 'dd mmmm')
Next Y

End Sub

;) [file name=userformdate.zip size=13866]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/userformdate.zip[/file]
 

Pièces jointes

  • userformdate.zip
    13.5 KB · Affichages: 15
  • userformdate.zip
    13.5 KB · Affichages: 17
  • userformdate.zip
    13.5 KB · Affichages: 17

Thierry78

XLDnaute Nouveau
Salut nico64,

Voici la réponse à ton problème, il s'agissait d'une mauvaise définition des valeurs de tes cellules dans le chargement de ton userform. Le reste fonctionnait déjà très bien!

A+

Thierry78 [file name=userformdate_20050407153916.zip size=17014]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/userformdate_20050407153916.zip[/file]
 

Pièces jointes

  • userformdate_20050407153916.zip
    16.6 KB · Affichages: 16
N

nico 64

Guest
aprés verification je m'aperçoit que la courbe affiche un jour en moins que celui demandé !!! (elle décale d'1 jour)

-serait-il possible de modifier ceci ?
-ou faut-il agir pour que l'userform prenne en compte de nouvelles données ?

merci d'avance.

voici le dernier code et le fichier:

Option Explicit


Private Sub CommandButton1_Click()
Dim X As Byte, i As Byte
Dim j As Integer, Debut As Integer, Fin As Integer
Dim Plage As Range, Plage2 As Range

If ListBox1.Value = '' Then Exit Sub
If ComboBox1.ListIndex = -1 Or ComboBox2.ListIndex = -1 Then Exit Sub

If ComboBox1.ListIndex > ComboBox2.ListIndex Then
MsgBox 'La date de fin ne peut pas etre antérieure à la date de début .'
Exit Sub
End If

Debut = ComboBox1.ListIndex + 2
Fin = ComboBox2.ListIndex + 2

Set Plage = Feuil1.Range('A' & Debut & ':A' & Fin)

Application.ScreenUpdating = False
Worksheets(1).ChartObjects('Graphique 1').Activate

For j = ActiveChart.SeriesCollection.Count To 1 Step -1
ActiveChart.SeriesCollection(j).Delete
Next j

For i = 0 To ListBox1.ListCount - 1 'boucle sur les éléments de la listbox

If ListBox1.Selected(i) = True Then
X = X + 1

ActiveChart.SeriesCollection.NewSeries
Set Plage2 = Feuil1.Range(Feuil1.Cells(Debut, i + 2).Address & ':' & Feuil1.Cells(Fin, i + 2).Address)

ActiveChart.SeriesCollection(X).Values = Plage2
If X = 1 Then ActiveChart.SeriesCollection(X).XValues = Plage
ActiveChart.SeriesCollection(X).Name = ListBox1.List(i) ' nom de la courbe
ActiveChart.SeriesCollection(X).Border.ColorIndex = i + 4
End If

Next i


Application.ScreenUpdating = True

End Sub


Private Sub Label1_Click()

End Sub

Private Sub UserForm_Initialize()
Dim X As Byte
Dim Y As Integer

For X = 2 To 6
ListBox1.AddItem Worksheets('Feuil1').Cells(1, X).Value
Next X

For Y = 3 To 366
If Worksheets('feuil1').Range('A' & Y).Value = '' Then
GoTo suite:
Else
ComboBox1.AddItem Format(Feuil1.Range('A' & Y), 'dd mmmm')
ComboBox2.AddItem Format(Feuil1.Range('A' & Y), 'dd mmmm')
End If
Next Y
suite:
End Sub
[file name=userformdate_20050407153916_20050407164501.zip size=17014]http://www.excel-downloads.com/components/com_simpleboard/uploaded/files/userformdate_20050407153916_20050407164501.zip[/file]
 

Pièces jointes

  • userformdate_20050407153916_20050407164501.zip
    16.6 KB · Affichages: 18

Thierry78

XLDnaute Nouveau
rien de bien méchant,

Il s'agit d'un mauvais calcul quand à l'estimation du numéro de la ligne de la plage par rapport à la position de la listindex:

Debut = ComboBox1.ListIndex + 3
Fin = ComboBox2.ListIndex + 3

et non pas

Debut = ComboBox1.ListIndex + 2
Fin = ComboBox2.ListIndex + 2

A+

Thierry78
 
N

nico64

Guest
ok ça marche merci
:) :lol: :) B)

mais comment faut-il modifier le code pour pouvoir ajouter des valeurs. car là si j'ajoute des dates elles n'apparaissent pas
si tu vois une solution.

apres j'arrete de t'embeter !

je pensais que la selection des dates se faisait sur cet ligne de code:

For Y = 3 To 366
If Worksheets('feuil1').Range('A' & Y).Value = '' Then

mais apparement non !
:S
 

Thierry78

XLDnaute Nouveau
Voilà,

En m'appercevant que ça fonctionnait tout à l'heure je n'ai pas voulu le modifier, mais il s'agit exactement du même problème qu'au début! Il suffit de modiier la définition de la valeur a ajouter dans la liste pour y arriver:

For Y = 3 To 366
If Worksheets('feuil1').Range('A' & Y).Value = '' Then
GoTo suite:
Else
ComboBox1.AddItem Format(Worksheets('Feuil1').Cells(Y, 1), 'dd mmmm')
ComboBox2.AddItem Format(Worksheets('Feuil1').Cells(Y, 1), 'dd mmmm')
End If
Next Y
suite:

Et ça marche! :-D

Bonne soirée,

Thierry78
 

Discussions similaires

Réponses
11
Affichages
295
Réponses
29
Affichages
924
Réponses
17
Affichages
840

Statistiques des forums

Discussions
312 216
Messages
2 086 351
Membres
103 195
dernier inscrit
martel.jg