Bonsoir à tous
j'ai un fichier excel composé de plusieurs onglets, les données comptables de chaque mois correspond à un onglet, et chaque onglet se compose de 3 colonne à savoir : numéro du compte / libellé / et montant ; je cherche à développer un macro pour comparer et extraire les comptes ayant une variation qui dépasse une pourcentage à saisir dans un textbox ce qui donne un userform avec :
combobox 1 : le mois à comparer
combobox 2 : le mois à comparer avec
Textbox1 : Pour saisir le pourcentage de variation (si je saisie 20% la listbox sera alimenter avec les comptes qui ont enregistrés une variation d'au moins 20%)
Lisbox : Pour recevoir le résultat:
Pour alimenter Cmb1 et cmb2 :
Partie du code qui transforme le saisie dans la textbox en pourcentage développé par Patrick à qui je passe un bonsoir
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 Private Sub UserForm_Initialize() ComboBox1.Clear For Each Ws In ThisWorkbook.Worksheets If Ws.Name <> "ACCEUIL" And Ws.Name <> "Vente" And Ws.Name <> "COMPAR" And Ws.Name <> "ENERGIE" And Ws.Name <> "GRAPHIQUE" And Ws.Name <> "GRAPH" And Ws.Name <> "ANALYSE" And Ws.Name <> "H2SO4" And Ws.Name <> "Oleum" And Ws.Name <> "Vapeur" And Ws.Name <> "AlF3" And Ws.Name <> "Anhydrite" And Ws.Name <> "RESULTAT" And Ws.Name <> "RESULTATA" And Ws.Name <> "BALANCE" And Ws.Name <> "RapportM" Then ComboBox1.AddItem Ws.Name ComboBox2.AddItem Ws.Name End If Next Ws TextBox1.Value = Format(TextBox1.Value, "0.00%") End Sub
Je bloque ici : une fois j'ai choisi le mois et le mois à comparer avec comment déclarer la feuille source de données
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If Not InStr("47 48 49 50 51 52 53 54 55 56 57 63 44 ", KeyAscii) > 0 Then KeyAscii = 0 End Sub Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Len(TextBox1) > 1 Then TextBox1 = Replace(TextBox1, "%", "") & "%" 'Chr(keysacii) TextBox1 = Replace(Replace(TextBox1, "?", ","), ".", ",") ' POUR CE QUI N'ON PAS LE PAVE NUMERIQUE SUR LE COTE DU CLAVIER (PC PORTABLE) End Sub
j'ai fait comme ça mais ça marche pas :
Merci à vous tous et bonne fin journée
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 Private Sub CommandButton1_Click() Application.ScreenUpdating = False Dim f1 As Worksheet Dim f2 As Worksheet Set f1 = ThisWorkbook.Sheets(ThisWorkbook.Sheets(UserForm2.ComboBox1.Value)) Set f2 = ThisWorkbook.Sheets(ThisWorkbook.Sheets(UserForm2.ComboBox2.Value)) Tablo = f1.Range("A2", "C" & f1.Range("C" & f1.Rows.Count).End(xlUp).Row) Tabloc = f2.Range("A2", "C" & f2.Range("C" & f2.Rows.Count).End(xlUp).Row) For i = LBound(Tablo, 1) To UBound(Tablo, 1) For j = LBound(Tabloc, 1) To UBound(Tabloc, 1) If Tablo(i, 1) = Tabloc(j, 1) And (Tablo(i, 3) - Tabloc(j, 3)) > Tabloc(j, 3) * CDbl(TextBox1.Value) Then ' message juste pour tester la procédure MsgBox Tablo(i, 1) End If Next j Next i Application.ScreenUpdating = True End Sub
Partager