Code VBA - Renvoyer a la ligne dans un tableau

Bonjour a tous,

Je vous sollicite pour un petit coup de main pour connaitre le code exacte que je dois mettre dans mon userform1 pour que quand le valide il recopie les donné dans mon tableau en ligne suivante:

J'ai pas de connaissance en VBA, je mis suis mis seulement hier et j'ai jusque la réussie a codé ce que je voulais faire mais le je bloque malgré toutes mes recherche sur les forums, vidéo...

Je vous joins le fichier complet pour simplifier ma demande. Je pense que mon code est très amateurs et comporte beaucoup d'erreur mais je débute vraiment, j'ai juste une demi journée de pratique. Je suis preneur de tout les conseilles et surtout de la solution exacte.

Merci d'avance.

Mon code:

Private Sub CommandButton1_Click()

Sheets("Tableau").Range("C6") = TextBox2.Value

Sheets("Tableau").Range("B6") = TextBox4.Value

'Type de vente

'VN

If OptionButton11.Value = True Then

Sheets("Tableau").Range("D6") = OptionButton11.Caption

End If

' VD

If OptionButton12.Value = True Then

Sheets("Tableau").Range("D6") = OptionButton12.Caption

End If

If OptionButton12.Value = True Then

Sheets("Tableau").Range("F6") = CDbl(TextBox7.Value * 0.006)

End If

' VO

If OptionButton13.Value = True Then

Sheets("Tableau").Range("D6") = OptionButton13.Caption

End If

If OptionButton13.Value = True Then

Sheets("Tableau").Range("F6") = CDbl(TextBox7.Value * 0.006)

End If

'Modèle DS3

If OptionButton3.Value = True Then

Sheets("Tableau").Range("E6") = OptionButton3.Caption

End If

If OptionButton22.Value = True And OptionButton3.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 50

End If

If OptionButton23.Value = True And OptionButton3.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 100

End If

'Modèle DS4

If OptionButton1.Value = True Then

Sheets("Tableau").Range("E6") = OptionButton1.Caption

End If

If OptionButton22.Value = True And OptionButton1.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 60

End If

If OptionButton23.Value = True And OptionButton1.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 120

End If

'Modèle DS7

If OptionButton4.Value = True Then

Sheets("Tableau").Range("E6") = OptionButton4.Caption

End If

If OptionButton22.Value = True And OptionButton4.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 70

End If

If OptionButton23.Value = True And OptionButton4.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 140

End If

'Modèle DS9

If OptionButton2.Value = True Then

Sheets("Tableau").Range("E6") = OptionButton2.Caption

End If

If OptionButton22.Value = True And OptionButton2.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 100

End If

If OptionButton23.Value = True And OptionButton2.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 200

End If

'Modèle Hybride

If OptionButton5.Value = True Then

Sheets("Tableau").Range("E6") = OptionButton5.Caption

End If

If OptionButton22.Value = True And OptionButton5.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 100

End If

If OptionButton23.Value = True And OptionButton5.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 200

End If

'Modèle Electique

If OptionButton6.Value = True Then

Sheets("Tableau").Range("E6") = OptionButton6.Caption

End If

If OptionButton22.Value = True And OptionButton6.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 150

End If

If OptionButton23.Value = True And OptionButton6.Value = True And OptionButton11.Value = True Then

Sheets("Tableau").Range("F6") = 250

End If

'Fmr 1

If OptionButton7.Value = True Then

Sheets("Tableau").Range("G6") = OptionButton7.Caption

Sheets("Tableau").Range("H6") = 20

End If

' Fmr 2

If OptionButton9.Value = True Then

Sheets("Tableau").Range("G6") = OptionButton9.Caption

Sheets("Tableau").Range("H6") = 55

End If

'Fmr 3

If OptionButton8.Value = True Then

Sheets("Tableau").Range("G6") = OptionButton8.Caption

Sheets("Tableau").Range("H6") = 75

End If

'Fmr Vo

If OptionButton10.Value = True Then

Sheets("Tableau").Range("G6") = OptionButton10.Caption

Sheets("Tableau").Range("H6") = 30

End If

' Financement

' Comptant

If OptionButton18.Value = True Then

Sheets("Tableau").Range("i6") = OptionButton18.Caption

Sheets("Tableau").Range("J6") = 0

End If

'LLD

If OptionButton19.Value = True Then

Sheets("Tableau").Range("I6") = OptionButton19.Caption

Sheets("Tableau").Range("J6") = CDbl(TextBox3.Value - TextBox5.Value - TextBox6.Value) / 1.2

End If

'LOA

If OptionButton20.Value = True Then

Sheets("Tableau").Range("I6") = OptionButton20.Caption

Sheets("Tableau").Range("J6") = CDbl(TextBox3.Value - TextBox5.Value) / 1.2

End If

'Credit

If OptionButton21.Value = True Then

Sheets("Tableau").Range("I6") = OptionButton21.Caption

Sheets("Tableau").Range("J6") = CDbl(TextBox3.Value - TextBox5.Value)

End If

'Contrat de service

' Extention de garantie

If OptionButton14.Value = True Then

Sheets("Tableau").Range("k6") = OptionButton14.Caption

End If

If OptionButton18.Value = True And OptionButton14.Value = True Then

Sheets("Tableau").Range("L6") = 0

End If

If OptionButton19.Value = True And OptionButton14.Value = True Then

Sheets("Tableau").Range("L6") = 0

End If

If OptionButton20.Value = True And OptionButton14.Value = True Then

Sheets("Tableau").Range("L6") = 0

End If

If OptionButton21.Value = True And OptionButton14.Value = True Then

Sheets("Tableau").Range("L6") = 0

End If

' Extention de garantie et entretien

If OptionButton15.Value = True Then

Sheets("Tableau").Range("k6") = OptionButton15.Caption

End If

If OptionButton18.Value = True And OptionButton15.Value = True Then

Sheets("Tableau").Range("L6") = 20

End If

If OptionButton19.Value = True And OptionButton15.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

If OptionButton20.Value = True And OptionButton15.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

If OptionButton21.Value = True And OptionButton15.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

' Freedrive

If OptionButton16.Value = True Then

Sheets("Tableau").Range("k6") = OptionButton16.Caption

End If

If OptionButton18.Value = True And OptionButton16.Value = True Then

Sheets("Tableau").Range("L6") = 20

End If

If OptionButton19.Value = True And OptionButton16.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

If OptionButton20.Value = True And OptionButton16.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

If OptionButton21.Value = True And OptionButton16.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

'Maintenance

If OptionButton17.Value = True Then

Sheets("Tableau").Range("k6") = OptionButton17.Caption

End If

If OptionButton18.Value = True And OptionButton17.Value = True Then

Sheets("Tableau").Range("L6") = 20

End If

If OptionButton19.Value = True And OptionButton17.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

If OptionButton20.Value = True And OptionButton17.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

If OptionButton21.Value = True And OptionButton17.Value = True Then

Sheets("Tableau").Range("L6") = 40

End If

' Bonus vo

If CheckBox20 = True Then

Sheets("Tableau").Range("N6") = 50

Sheets("Tableau").Range("M6") = "Oui"

End If

If CheckBox20 = Fasle Then

Sheets("Tableau").Range("N6") = 0

Sheets("Tableau").Range("M6") = "Non"

End If

'Réinitialisation après validation

Unload Me
UserForm1.Show

End Sub

Bonjour et bienvenue

Je pense que la première chose à faire serait de renommer vos objets dans un ordre logique.

exemples :
- grille 1 et grille 2 sont nommés option 22 et 23. --> vous pourriez les nommer Option1, option2
- textbox client --> textbox1 et textboxdate --> textbox2
- checkbox bonus --> Checkbox1 au lieu de checkbox20

Ce sera plus simple pour construire ou adapter le code

ensuite votre feuille Tableau, est-ce un problème de commencer sur la ligne 1 et colonne A ?

bonjour,

ok je vais taché de mettre un peux de logique dans ce code mais encore hier cela était du chinois pour moi. Je suis arrivé a ce code avec énormément de mal.

mais je vais suivre t'es conseille.

Merci

Bonjour Diapason et bonjour DAN

D'aprés les lignes de codes tu as trouvé comment renvoyer les informations de ton userform sur la ligne 6 de ton onglet "Tableau".

Le principe du vba pour remplir un tableau est de ne pas indiquer soit même le numéro de ligne qui doit rester une variable à trouver lors de la validation des données.

- Ton code dois commencer par la recherche de la dernière ligne non vide puis ajouter 1 pour trouver la ligne qui sera à valider.

Exemple de début de codage :

Private Sub CommandButton1_Click()
Dim DERLIGNE as long
DERLIGNE=Worksheets("Tableau").Range("A65536").End(xlUp).Row + 1

' Ensuite on utilise DERLIGNE comme numéro de ligne pour valider

Sheets("Tableau").Range("C" & DERLIGNE) = TextBox2.Value

Sheets("Tableau").Range("B" & DERLIGNE) = TextBox4.Value

'Type de vente  .........

Bon courage pour le reste c'est difficile au début mais faut continuer.. Cependant Dan à raison c'est bien plus facile quand tout est bien dans l'ordre.

d'ailleurs la touche "Tab" qui permet de passer d'une textbox à une autre en tient compte de cet ordre.

ok je vais taché de mettre un peux de logique dans ce code mais encore hier cela était du chinois pour moi. Je suis arrivé a ce code avec énormément de mal.

Laissez le code de coté. Mettez d'abord de l'ordre dans les noms de textbox, checkbox. Suivez une logique croissante. Vous allez y gagner en construction du code qui sera plus petit en matière de lignes et du coup plus rapide aussi.

Comme XmenPL le souligne, avec la touche TAB cela vous permettre de passer d'un objet à l'autre en suivant une logique pour compléter l'usf

Un grand merci a Dan et Xmenpl

J'ai suivie vos conseille et cela fonctionne. Je réorganise tout maintenant.

Rechercher des sujets similaires à "code vba renvoyer ligne tableau"