Bonjour à tous,
Je me permets de solliciter votre aide pour un problème de userform.
En effet, grâce à quelques aides j'ai crée une boite de dialogue me permettant de consulter et compléter un onglet intitulé "facturation".
Le problème est que j'ai ajouté une fonction me permettant de classer par ordre croissant ou décroissant les différents critères de la listview (n° de compte - agence - client) malheureusement les valeurs de varient pas en fonction du compte selectionné.
Vous trouverez ci-dessous le code inséré :
Je me permets de solliciter votre aide pour un problème de userform.
En effet, grâce à quelques aides j'ai crée une boite de dialogue me permettant de consulter et compléter un onglet intitulé "facturation".
Le problème est que j'ai ajouté une fonction me permettant de classer par ordre croissant ou décroissant les différents critères de la listview (n° de compte - agence - client) malheureusement les valeurs de varient pas en fonction du compte selectionné.
Vous trouverez ci-dessous le code inséré :
Code:
Option Compare Text 'POUR IGNORER DIFFERENCE MAJUSCULES / MINUSCULES
'------ Ecriture des champs renseignés dans la Boite de Dialogue sur l'onglet Facturation ------'
Private Sub BoutonValider_Click()
If ComboBox1.Value = "Janvier" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 10).Value = Val(TextBox1.Text)
If ComboBox1.Value = "Janvier" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 11).Value = Me.TextBox2.Value
If ComboBox1.Value = "Janvier" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 12).Value = Me.TextBox3.Value
If ComboBox1.Value = "Février" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 13).Value = Me.TextBox1.Value
If ComboBox1.Value = "Février" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 14).Value = Me.TextBox2.Value
If ComboBox1.Value = "Février" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 15).Value = Me.TextBox3.Value
If ComboBox1.Value = "Mars" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 16).Value = Me.TextBox1.Value
If ComboBox1.Value = "Mars" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 17).Value = Me.TextBox2.Value
If ComboBox1.Value = "Mars" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 18).Value = Me.TextBox3.Value
If ComboBox1.Value = "Avril" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 19).Value = Me.TextBox1.Value
If ComboBox1.Value = "Avril" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 20).Value = Me.TextBox2.Value
If ComboBox1.Value = "Avril" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 21).Value = Me.TextBox3.Value
If ComboBox1.Value = "Mai" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 22).Value = Me.TextBox1.Value
If ComboBox1.Value = "Mai" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 23).Value = Me.TextBox2.Value
If ComboBox1.Value = "Mai" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 24).Value = Me.TextBox3.Value
If ComboBox1.Value = "Juin" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 25).Value = Me.TextBox1.Value
If ComboBox1.Value = "Juin" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 26).Value = Me.TextBox2.Value
If ComboBox1.Value = "Juin" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 27).Value = Me.TextBox3.Value
If ComboBox1.Value = "Juillet" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 28).Value = Me.TextBox1.Value
If ComboBox1.Value = "Juillet" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 29).Value = Me.TextBox2.Value
If ComboBox1.Value = "Juillet" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 30).Value = Me.TextBox3.Value
If ComboBox1.Value = "Août" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 31).Value = Me.TextBox1.Value
If ComboBox1.Value = "Août" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 32).Value = Me.TextBox2.Value
If ComboBox1.Value = "Août" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 33).Value = Me.TextBox3.Value
If ComboBox1.Value = "Septembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 34).Value = Me.TextBox1.Value
If ComboBox1.Value = "Septembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 35).Value = Me.TextBox2.Value
If ComboBox1.Value = "Septembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 36).Value = Me.TextBox3.Value
If ComboBox1.Value = "Octobre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 37).Value = Me.TextBox1.Value
If ComboBox1.Value = "Octobre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 38).Value = Me.TextBox2.Value
If ComboBox1.Value = "Octobre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 39).Value = Me.TextBox3.Value
If ComboBox1.Value = "Novembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 40).Value = Me.TextBox1.Value
If ComboBox1.Value = "Novembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 41).Value = Me.TextBox2.Value
If ComboBox1.Value = "Novembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 42).Value = Me.TextBox3.Value
If ComboBox1.Value = "Décembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 43).Value = Me.TextBox1.Value
If ComboBox1.Value = "Décembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 44).Value = Me.TextBox2.Value
If ComboBox1.Value = "Décembre" Then ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 45).Value = Me.TextBox3.Value
End Sub
Private Sub ListView1_Click()
If ComboBox1.Value = "Janvier" Then Me.TextBox2.Value = "=Application.Worksheet.VLOOKUP(Me.ListView1.SelectedItem,Commercial!A4:K200,10,FALSE)"
If ComboBox1.Value = "Janvier" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 11).Value
If ComboBox1.Value = "Janvier" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 12).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Février" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 13).Value
If ComboBox1.Value = "Février" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 14).Value
If ComboBox1.Value = "Février" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 15).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Mars" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 16).Value
If ComboBox1.Value = "Mars" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 17).Value
If ComboBox1.Value = "Mars" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 18).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Avril" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 19).Value
If ComboBox1.Value = "Avril" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 20).Value
If ComboBox1.Value = "Avril" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 21).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Mai" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 22).Value
If ComboBox1.Value = "Mai" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 23).Value
If ComboBox1.Value = "Mai" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 24).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Juin" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 25).Value
If ComboBox1.Value = "Juin" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 26).Value
If ComboBox1.Value = "Juin" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 27).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Juillet" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 28).Value
If ComboBox1.Value = "Juillet" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 29).Value
If ComboBox1.Value = "Juillet" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 30).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Août" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 31).Value
If ComboBox1.Value = "Août" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 32).Value
If ComboBox1.Value = "Août" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 33).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Septembre" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 34).Value
If ComboBox1.Value = "Septembre" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 35).Value
If ComboBox1.Value = "Septembre" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 36).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Octobre" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 37).Value
If ComboBox1.Value = "Octobre" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 38).Value
If ComboBox1.Value = "Octobre" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 39).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Novembre" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 40).Value
If ComboBox1.Value = "Novembre" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 41).Value
If ComboBox1.Value = "Novembre" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 42).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
If ComboBox1.Value = "Décembre" Then Me.TextBox1.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 43).Value
If ComboBox1.Value = "Décembre" Then Me.TextBox2.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 44).Value
If ComboBox1.Value = "Décembre" Then Me.TextBox3.Value = ActiveSheet.Cells(Me.ListView1.SelectedItem.Index + 5, 45).Value
Me.TextBox4.Text = Sheets("Commercial").Cells(Me.ListView1.SelectedItem.Index + 4, 11).Value
Me.Label4.Caption = Me.ListView1.SelectedItem.Text & " - " _
& Me.ListView1.SelectedItem.ListSubItems(1).Text & " - " & Me.ListView1.SelectedItem.ListSubItems(2).Text
TextBox1.Value = Format(TextBox1.Value, "# ,##0.00 [-40C]")
TextBox2.Value = Format(TextBox2.Value, "0.00%")
TextBox3.Value = Format(TextBox3.Value, "# ,##0.00 [-40C]")
End Sub
'----------- MISE EN FORME ET RECHERCHE DES INFOS DU COMBOX1 -------------'
Private Sub UserForm_Initialize()
For i = 1 To 12 ' CHARGEMENT DES MOIS DANS UNE ANNEE, ET MISE EN MAJUSCULES
ComboBox1.AddItem Format(Format("1/" & i, "mmmm"), ">")
Next i
ComboBox1.Value = Format(Format(CDate(Date), "mmmm"), ">")
With Me.ListView1
.Gridlines = True
.View = 3
.MultiSelect = True
.FullRowSelect = True
With .ColumnHeaders
.Add , , "N° COMPTE", 80
.Add , , "AGENCE", 80
.Add , , "CLIENT", 190 ', lvwColumnRight
End With
End With
Worksheets("Facturation").Activate
With Me.ListView1
For j = 6 To ActiveSheet.Range("A65536").End(xlUp).Row
.ListItems.Add , , ActiveSheet.Cells(j, 1).Value 'N° DE COMPTE
.ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(j, 2).Value ' AGENCE
.ListItems(.ListItems.Count).ListSubItems.Add , , ActiveSheet.Cells(j, 3).Value ' NON CLIENT
Next j
End With
For Each FEUILLE In ThisWorkbook.Worksheets
If FEUILLE.Name = ComboBox1.Value Then FEUILLE.Activate
Next
N°LIGNE = 5
Me.TextBox1.Text = ActiveSheet.Cells(N°LIGNE, 1).Value
Me.TextBox2.Text = ActiveSheet.Cells(N°LIGNE, 2).Value
Me.TextBox3.Text = ActiveSheet.Cells(N°LIGNE, 3).Value
Me.Label4.Caption = Me.ComboBox1.Value & " - " & Me.ListView1.ListItems(1).Text & " - " _
& Me.ListView1.ListItems(1).ListSubItems(1).Text & " - " & Me.ListView1.ListItems(1).ListSubItems(2).Text
End Sub
' ------ Tri lors de la sélection d'une colonne ----------'
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
ListView1.Sorted = False
ListView1.SortKey = ColumnHeader.Index - 1
If ListView1.SortOrder = lvwAscending Then
ListView1.SortOrder = lvwDescending
Else
ListView1.SortOrder = lvwAscending
End If
ListView1.Sorted = True
End Sub
'---------- Multiplication dans la TextBox3 ------------'
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
On Error Resume Next ' Si ce n'est pas une saisie conforme!
TextBox2 = Replace(TextBox2.Value, ".", ",")
TextBox3 = TextBox1 * TextBox2 / 100
TextBox2 = TextBox2 & "%"
TextBox1.Value = Format(TextBox1.Value, "# ,##0.00 [-40C]")
TextBox3.Value = Format(TextBox3.Value, "# ,##0.00 [-40C]")
End Sub
'Tester : Val(TextBox1.Value)pour valeurs numeriques'