Allèger un code
Fermé
lanetmel
Messages postés
200
Date d'inscription
mercredi 24 août 2011
Statut
Membre
Dernière intervention
15 mars 2018
-
28 févr. 2012 à 21:41
lermite222 Messages postés 8702 Date d'inscription dimanche 8 avril 2007 Statut Contributeur Dernière intervention 22 janvier 2020 - 5 mars 2012 à 16:25
lermite222 Messages postés 8702 Date d'inscription dimanche 8 avril 2007 Statut Contributeur Dernière intervention 22 janvier 2020 - 5 mars 2012 à 16:25
A voir également:
- Allèger un code
- Code asci - Guide
- Freewifi secure code ✓ - Forum Réseau
- Code 80072efe ✓ - Forum Windows
- Netflix code - Guide
- Code puk maroc telecom ✓ - Forum Mobile
2 réponses
lanetmel
Messages postés
200
Date d'inscription
mercredi 24 août 2011
Statut
Membre
Dernière intervention
15 mars 2018
4
4 mars 2012 à 21:57
4 mars 2012 à 21:57
On M'a aidé en message privé! Voici la réponse
Option Explicit
Private Sub cmdok_click()
Dim Lign As Long
Dim col1, col2, col3, col4, col5 As Integer
col1 = (ComboBox4.ListIndex * 2) + 11
col2 = (ComboBox5.ListIndex * 2) + 11
col3 = (ComboBox6.ListIndex * 2) + 11
col4 = (ComboBox7.ListIndex * 2) + 11
col5 = (ComboBox3.ListIndex * 2) + 11
'--- en feuil Infos va chercher la ligne vide.....
With Sheets("Infos")
'......comprise entre la ligne 5 et la dernière ligne remplie
For Lign = 5 To .Range("a" & Rows.Count).End(xlUp).Row + 1
'.... s'il n'y a pas d'erreur (déclenchée par une formule)
If IsError(.Cells(Lign, 1)) Then
'si elle est vide alors...
ElseIf .Cells(Lign, 1) = "" Then
'on écrit dedans !!!
.Cells(Lign, 1) = (TextBox3.Value)
.Cells(Lign, 2) = (TextBox4.Value)
.Cells(Lign, 3) = (TextBox5.Value)
.Cells(Lign, 61) = (TextBox20.Value)
.Cells(Lign, 66) = (TextBox21.Value)
.Cells(Lign, 4) = (ComboBox2.Value)
.Cells(Lign, 5) = (ComboBox12.Value)
.Cells(Lign, 6) = (ComboBox1.Value)
.Cells(Lign, 7) = (TextBox18.Value)
.Cells(Lign, 8) = (ComboBox8.Value)
.Cells(Lign, 9) = (ComboBox9.Value)
.Cells(Lign, 63) = (ComboBox10.Value)
.Cells(Lign, 64) = (TextBox16.Value)
.Cells(Lign, 65) = (ComboBox13.Value)
.Cells(Lign, 150) = (TextBox19.Value)
.Cells(Lign, col1) = (TextBox7.Value)
.Cells(Lign, col1 + 1) = (TextBox12.Value)
.Cells(Lign, col2) = (TextBox8.Value)
.Cells(Lign, col2 + 1) = (TextBox15.Value)
.Cells(Lign, col3) = (TextBox9.Value)
.Cells(Lign, col3 + 1) = (TextBox14.Value)
.Cells(Lign, col4) = (TextBox10.Value)
.Cells(Lign, col4 + 1) = (TextBox13.Value)
.Cells(Lign, col5) = (TextBox6.Value)
.Cells(Lign, col5 + 1) = (TextBox11.Value)
.Cells(Lign, 60) = (ComboBox11.Value)
.Cells(Lign, 163) = (TextBox23.Value)
.Cells(Lign, 164) = (TextBox24.Value * TextBox20.Value)
Exit For
End If
Next Lign
End With
Unload Me
End Sub
Private Sub CmdAnnuler_Click()
Unload Me
Si ça peut aider d'autres personnes!
Option Explicit
Private Sub cmdok_click()
Dim Lign As Long
Dim col1, col2, col3, col4, col5 As Integer
col1 = (ComboBox4.ListIndex * 2) + 11
col2 = (ComboBox5.ListIndex * 2) + 11
col3 = (ComboBox6.ListIndex * 2) + 11
col4 = (ComboBox7.ListIndex * 2) + 11
col5 = (ComboBox3.ListIndex * 2) + 11
'--- en feuil Infos va chercher la ligne vide.....
With Sheets("Infos")
'......comprise entre la ligne 5 et la dernière ligne remplie
For Lign = 5 To .Range("a" & Rows.Count).End(xlUp).Row + 1
'.... s'il n'y a pas d'erreur (déclenchée par une formule)
If IsError(.Cells(Lign, 1)) Then
'si elle est vide alors...
ElseIf .Cells(Lign, 1) = "" Then
'on écrit dedans !!!
.Cells(Lign, 1) = (TextBox3.Value)
.Cells(Lign, 2) = (TextBox4.Value)
.Cells(Lign, 3) = (TextBox5.Value)
.Cells(Lign, 61) = (TextBox20.Value)
.Cells(Lign, 66) = (TextBox21.Value)
.Cells(Lign, 4) = (ComboBox2.Value)
.Cells(Lign, 5) = (ComboBox12.Value)
.Cells(Lign, 6) = (ComboBox1.Value)
.Cells(Lign, 7) = (TextBox18.Value)
.Cells(Lign, 8) = (ComboBox8.Value)
.Cells(Lign, 9) = (ComboBox9.Value)
.Cells(Lign, 63) = (ComboBox10.Value)
.Cells(Lign, 64) = (TextBox16.Value)
.Cells(Lign, 65) = (ComboBox13.Value)
.Cells(Lign, 150) = (TextBox19.Value)
.Cells(Lign, col1) = (TextBox7.Value)
.Cells(Lign, col1 + 1) = (TextBox12.Value)
.Cells(Lign, col2) = (TextBox8.Value)
.Cells(Lign, col2 + 1) = (TextBox15.Value)
.Cells(Lign, col3) = (TextBox9.Value)
.Cells(Lign, col3 + 1) = (TextBox14.Value)
.Cells(Lign, col4) = (TextBox10.Value)
.Cells(Lign, col4 + 1) = (TextBox13.Value)
.Cells(Lign, col5) = (TextBox6.Value)
.Cells(Lign, col5 + 1) = (TextBox11.Value)
.Cells(Lign, 60) = (ComboBox11.Value)
.Cells(Lign, 163) = (TextBox23.Value)
.Cells(Lign, 164) = (TextBox24.Value * TextBox20.Value)
Exit For
End If
Next Lign
End With
Unload Me
End Sub
Private Sub CmdAnnuler_Click()
Unload Me
Si ça peut aider d'autres personnes!
lermite222
Messages postés
8702
Date d'inscription
dimanche 8 avril 2007
Statut
Contributeur
Dernière intervention
22 janvier 2020
1 193
Modifié par lermite222 le 5/03/2012 à 16:26
Modifié par lermite222 le 5/03/2012 à 16:26
Re,
Oui mais... Y a encore moyen d'optimiser
Dans tout les Tag des contrôles du UF tu met la colonnes de destination, par exemple
dans TextBox3.tag tu met 1
TextBox4.tag tu met 2
TextBox5.tag tu met 3
TextBox20.tag tu met 6
TextBox21.tag tu met 66
ComboBox2.tag tu met 4
ComboBox12.tag tu met 5
etc.. pour tous
Et la macro devient..
Tu voulais "alléger".. beh voila..
Reste encore la recherche de la ligne, tu à des lignes vides intercalées ?
A+
Si tu te cognes à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide. ;-)(Confucius)
NOTE : Je ne répond pas aux MP pour les questions techniques.
Oui mais... Y a encore moyen d'optimiser
Dans tout les Tag des contrôles du UF tu met la colonnes de destination, par exemple
dans TextBox3.tag tu met 1
TextBox4.tag tu met 2
TextBox5.tag tu met 3
TextBox20.tag tu met 6
TextBox21.tag tu met 66
ComboBox2.tag tu met 4
ComboBox12.tag tu met 5
etc.. pour tous
Et la macro devient..
Private Sub cmdok_click()
Dim Lign As Long, Ctl As Control
'--- en feuil Infos va chercher la ligne vide.....
With Sheets("Infos")
For Lign = 5 To .Range("a" & Rows.Count).End(xlUp).Row + 1
'.... s'il n'y a pas d'erreur (déclenchée par une formule)
If Not IsError(.Cells(Lign, 1)) And .Cells(Lign, 1) = "" Then
Exit For
End If
Next Lign
For Each Ctl In Me.Controls
If TypeOf Ctl Is MSForms.ComboBox Then
.Cells(Lign, Ctl.Tag) = (Ctl.ListIndex * 2) + 11
ElseIf TypeOf Ctl Is MSForms.TextBox Then
.Cells(Lign, Ctl.Tag) = Ctl.Value
End If
Next Ctl
End With
End Sub
Tu voulais "alléger".. beh voila..
Reste encore la recherche de la ligne, tu à des lignes vides intercalées ?
A+
Si tu te cognes à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide. ;-)(Confucius)
NOTE : Je ne répond pas aux MP pour les questions techniques.