Incrementation id formulaire
lol1304
Messages postés
10
Statut
Membre
-
Le Pingou Messages postés 12274 Date d'inscription Statut Contributeur Dernière intervention -
Le Pingou Messages postés 12274 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
je sais que ca à certainement dejas ete demandé mais je ne trouve pas de solution sur les forum ou du moins il semble y avoir des tonne de facon de faire...
je voudrais incrementer un numero id a chaque ouverture d'un formulaire, ce que j'ai enfin reussi a faire en suivant un tuto... mon probleme est que le numero 1 apparait bien mais il reste sur 1! car je n'arrive pas a inserer la derniere ligne du tuto a savoir:
Feuil3.Cells(derligne, 30) = Val(TextBox24)
cela me met une erreur 1004.
ci joint mon VBA sachant qu'il y à un commandboutton2 identique avec .show
d'avance merci.
je sais que ca à certainement dejas ete demandé mais je ne trouve pas de solution sur les forum ou du moins il semble y avoir des tonne de facon de faire...
je voudrais incrementer un numero id a chaque ouverture d'un formulaire, ce que j'ai enfin reussi a faire en suivant un tuto... mon probleme est que le numero 1 apparait bien mais il reste sur 1! car je n'arrive pas a inserer la derniere ligne du tuto a savoir:
Feuil3.Cells(derligne, 30) = Val(TextBox24)
cela me met une erreur 1004.
ci joint mon VBA sachant qu'il y à un commandboutton2 identique avec .show
d'avance merci.
Private Sub CommandButton1_Click()
'Feuil3.Cells(derligne, 30) = Val(TextBox24)
'message erreur case non remplie
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Or TextBox8 = "" Or TextBox12 = "jj/mm/aaaa" Or TextBox14 = "" Or TextBox17 = "" Or TextBox18 = "" Then
MsgBox ("les informations: nom, prénom, n°ss, sexe, date entrée, coef et H.hebdo sont indispensables !")
Else
'si tout est bon, remplir tableau
If Sheets("PERSONNEL").Range("b4") = "" Then
Sheets("PERSONNEL").Range("b4") = TextBox1
Else
'si tableau dejas remplis, creer une nouvelle ligne en bas
Sheets("PERSONNEL").ListObjects(1).ListRows.Add
End If
'enregistrement sur la derniere ligne de tableau
dlt = Sheets("PERSONNEL").Range("d1048576").End(xlUp).Row
'affectation case formulaire / tableau
Sheets("PERSONNEL").Range("b" & dlt) = TextBox1
Sheets("PERSONNEL").Range("c" & dlt) = TextBox2
Sheets("PERSONNEL").Range("e" & dlt) = TextBox3
Sheets("PERSONNEL").Range("d" & dlt) = TextBox4
Sheets("PERSONNEL").Range("g" & dlt) = TextBox5.Value
TextBox5 = Format(TextBox5, "mm/dd/yyyy")
Sheets("PERSONNEL").Range("f" & dlt) = TextBox6
Sheets("PERSONNEL").Range("v" & dlt) = TextBox7
Sheets("PERSONNEL").Range("h" & dlt) = TextBox8
Sheets("PERSONNEL").Range("i" & dlt) = CheckBox5
Sheets("PERSONNEL").Range("z" & dlt) = TextBox9
Sheets("PERSONNEL").Range("aa" & dlt) = TextBox10
Sheets("PERSONNEL").Range("ab" & dlt) = TextBox11
Sheets("PERSONNEL").Range("x" & dlt) = TextBox12
Sheets("PERSONNEL").Range("y" & dlt) = TextBox13
Sheets("PERSONNEL").Range("k" & dlt) = TextBox14.Value
TextBox14 = Format(TextBox12, "mm/dd/yyyy")
Sheets("PERSONNEL").Range("l" & dlt) = TextBox15.Value
TextBox15 = Format(TextBox15, "mm/dd/yyyy")
Sheets("PERSONNEL").Range("j" & dlt) = TextBox16
Sheets("PERSONNEL").Range("w" & dlt) = TextBox17
Sheets("PERSONNEL").Range("s" & dlt) = TextBox18
Sheets("PERSONNEL").Range("m" & dlt) = TextBox19
Sheets("PERSONNEL").Range("n" & dlt) = TextBox20
Sheets("PERSONNEL").Range("o" & dlt) = CheckBox1
Sheets("PERSONNEL").Range("p" & dlt) = CheckBox2
Sheets("PERSONNEL").Range("q" & dlt) = CheckBox3
Sheets("PERSONNEL").Range("r" & dlt) = CheckBox4
Sheets("PERSONNEL").Range("t" & dlt) = TextBox21
Sheets("PERSONNEL").Range("u" & dlt) = TextBox22
Sheets("PERSONNEL").Range("ac" & dlt) = TextBox23
Sheets("PERSONNEL").Range("ad" & dlt) = TextBox24
Unload UserForm1
End If
End Sub
Configuration: Windows / Chrome 85.0.4183.102
14 réponses
-
Bonjour
merci de lire ceci https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code, et d'éditer ton texte pour l'appliquer
-
vraiment désolé, le voici...
Private Sub CommandButton1_Click() 'Feuil3.Cells(derligne, 30) = Val(TextBox24) 'message erreur case non remplie If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Or TextBox8 = "" Or TextBox12 = "jj/mm/aaaa" Or TextBox14 = "" Or TextBox17 = "" Or TextBox18 = "" Then MsgBox ("les informations: nom, prénom, n°ss, sexe, date entrée, coef et H.hebdo sont indispensables !") Else 'si tout est bon, remplir tableau If Sheets("PERSONNEL").Range("b4") = "" Then Sheets("PERSONNEL").Range("b4") = TextBox1 Else 'si tableau dejas remplis, creer une nouvelle ligne en bas Sheets("PERSONNEL").ListObjects(1).ListRows.Add End If 'enregistrement sur la derniere ligne de tableau dlt = Sheets("PERSONNEL").Range("d1048576").End(xlUp).Row 'affectation case formulaire / tableau Sheets("PERSONNEL").Range("b" & dlt) = TextBox1 Sheets("PERSONNEL").Range("c" & dlt) = TextBox2 Sheets("PERSONNEL").Range("e" & dlt) = TextBox3 Sheets("PERSONNEL").Range("d" & dlt) = TextBox4 Sheets("PERSONNEL").Range("g" & dlt) = TextBox5.Value TextBox5 = Format(TextBox5, "mm/dd/yyyy") Sheets("PERSONNEL").Range("f" & dlt) = TextBox6 Sheets("PERSONNEL").Range("v" & dlt) = TextBox7 Sheets("PERSONNEL").Range("h" & dlt) = TextBox8 Sheets("PERSONNEL").Range("i" & dlt) = CheckBox5 Sheets("PERSONNEL").Range("z" & dlt) = TextBox9 Sheets("PERSONNEL").Range("aa" & dlt) = TextBox10 Sheets("PERSONNEL").Range("ab" & dlt) = TextBox11 Sheets("PERSONNEL").Range("x" & dlt) = TextBox12 Sheets("PERSONNEL").Range("y" & dlt) = TextBox13 Sheets("PERSONNEL").Range("k" & dlt) = TextBox14.Value TextBox14 = Format(TextBox12, "mm/dd/yyyy") Sheets("PERSONNEL").Range("l" & dlt) = TextBox15.Value TextBox15 = Format(TextBox15, "mm/dd/yyyy") Sheets("PERSONNEL").Range("j" & dlt) = TextBox16 Sheets("PERSONNEL").Range("w" & dlt) = TextBox17 Sheets("PERSONNEL").Range("s" & dlt) = TextBox18 Sheets("PERSONNEL").Range("m" & dlt) = TextBox19 Sheets("PERSONNEL").Range("n" & dlt) = TextBox20 Sheets("PERSONNEL").Range("o" & dlt) = CheckBox1 Sheets("PERSONNEL").Range("p" & dlt) = CheckBox2 Sheets("PERSONNEL").Range("q" & dlt) = CheckBox3 Sheets("PERSONNEL").Range("r" & dlt) = CheckBox4 Sheets("PERSONNEL").Range("t" & dlt) = TextBox21 Sheets("PERSONNEL").Range("u" & dlt) = TextBox22 Sheets("PERSONNEL").Range("ac" & dlt) = TextBox23 Sheets("PERSONNEL").Range("ad" & dlt) = TextBox24 Unload UserForm1 End If End Sub -
-
Bonjour,
Merci de préciser sur qu'elle ligne de votre code se produit l'erreur et indiquer l'erreur exact...!
De quel tuto vous faite référence...!
Si possible, vous pouvez mettre votre fichier à disposition sur https://www.cjoint.com/ et poster le lien!
Salutations
Le Pingou
-
-
Bonjour le fil, bonjour le forum,
Le fichier nous aurait permis d'optimiser tes codes, mais...
Je te propose ce code qui, à l'ouverture de l'Userform, affichera la plus grande valeur de la colonne AD (=30) de l'onglet Feuil3 plus 1.
Dans la procédure Click du CommandButton1, il ne te restera plus qu'à renvoyer la valeur de la Textbox24 dans la première ligne vide de la colonne 30 de l'onglet Feuil3...
Le code :Private Sub UserForm_Initialize() Dim O As Worksheet Dim DL As Integer Set O = Worksheets("Feuil3") DL = O.Cells(Application.Rows.Count, "AD").End(xlUp).Row Me.TextBox24.Value = Application.WorksheetFunction.Max(O.Range("AD1:AD" & DL)) + 1 End Sub
-
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
Bonjour ThauTheme et bien évidement les autre aussi...
ton code fonctionne mais le numéro ne s'incrémente pas, il reste inexorablement sur 1
aurai-tu une idee de la manip stp.
aussi, serait il possible de mettre sous forme "001"
merci -
Bonjour,
modifier cette ligne:Application.WorksheetFunction.Max(O.Range("AD1:AD" & DL)) + 1
comme ceci;Format(Application.WorksheetFunction.Max(O.Range("AD1:AD" & DL)) + 1, "0000")
-
bonjour,
merci le pingou pour la mise en forme,
il me reste le probleme du n° qui ne s'incrémente pas, en fait si je note "1" dans la ligne 1 colonne AD de ma feuille ca fonctionne très bien mais mon tableau commence à la ligne 4.
y aurait il quelqu'un pour m'aiguillé car la solution est certainement très simple mais quand on sait pas eh ben... on cherche, on s'énerve mais... on sait pas
-
-
Bonjour,
Si je vous ai bien compris, dans la ligne d'instruction vous remplacez le AD1... par AD4
-
-
Bonjour,
Ca ne marche pas n'est pas une réponse qui permet de vous aider.
Qu'elle erreur recevez-vous ?
Autre solution, mettre le fichier à disposition sur https://mon-partage.fr/ ou https://www.cjoint.com/ et poster le lien.
Note j'ai vue au passage que vous cherchez la valeur dans la TextBox24, alors d'où vient la valeur de cette TextBox.?????
-
oui vous avez raison!
en fait ca ne me met aucune erreur, seulement le formulaire enregistre toujours 0001 sur toute les lignes.
voici le lien du fichier et merci pour votre intérêt,
https://mon-partage.fr/f/ZFWU3ecM/ -
Bonjour,
Merci de me dire s'il s'agit bien du N°Id du formulaire que vous enregistrez dans la colonne "AD" de la feuille "Personnel " Oui Non ???
-
Bonjour,
Voir petite explication sur la feuille "Personnel".
Le lien: https://mon-partage.fr/f/y1pfzpTS/
-
bonjour,
c'est bien le N° ID pour la colonne AD feuille "Personnel"
votre solution est magique, cela fonctionne mais je suis obligé de refaire la manipulation a chaque enregistrement.
n'est ce pas le code VBA qui enregistrerais le nombre en texte? -