Numérotation automatique dans Userform

Antho35

XLDnaute Occasionnel
Bonjour,

J'ai un petit probléme dans un userform. Je m'explique j'ai trois userform (ajout, Modif, supp). Quandje supprime la derniére demande, et que je repasse en ajout, la chronologie se suit il récupére le num de la demande supprime. Cependant quand je supprime des demande avant la derniére ligne, il me créer un doublins avec le numéro de la derniére ligne. Je voudrais bien joindre un fichier mais il dépasse les 12Mo et comme je ne vois pas ce qui pose probléme, le mieux serai de le mettre en entier.

donc dans un premier temp voici le code d'ajout

Code:
Private Sub CommandButton1_Click()
Dim ligne As Integer
ligne = ActiveCell.Row
Range("B2").Select
'If Len(Sheets("SYNTHESE_AUTRES").Cells(ligne, 2))= Then
If Range("B2").Value = "" Then
ligne = Range("SYNTHESE_AUTRES!B65500").End(xlUp).Row + 1
Else
ligne = Range("SYNTHESE_AUTRES!B65500").End(xlUp).Row + 1
End If
Sheets("SYNTHESE_AUTRES").Cells(ligne, 2) = ligne
'End If
Sheets("SYNTHESE_AUTRES").Cells(ligne, 2) = Format(TextBox7, "2_2010_0000")
Sheets("SYNTHESE_AUTRES").Cells(ligne, 3) = Format(TextBox2, "mm/dd/yyyy")
Sheets("SYNTHESE_AUTRES").Cells(ligne, 4) = ComboBox1.Value
Sheets("SYNTHESE_AUTRES").Cells(ligne, 5) = ComboBox2.Value
Sheets("SYNTHESE_AUTRES").Cells(ligne, 6) = Format(TextBox4, "dd/mm/yyyy")
Sheets("SYNTHESE_AUTRES").Cells(ligne, 7) = Format(TextBox5, "hh:mm")
Sheets("SYNTHESE_AUTRES").Cells(ligne, 8) = ComboBox3.Value
Sheets("SYNTHESE_AUTRES").Cells(ligne, 9) = ComboBox4.Value
Sheets("SYNTHESE_AUTRES").Cells(ligne, 12) = TextBox6.Value
ComboBox1 = "Sélectionnez votre service"
ComboBox2 = "Sélectionnez le type de transport"
ComboBox3 = "Sélectionnez le lieu de RDV"
ComboBox4 = "Sélectionnez le motif"
TextBox7 = Format(TextBox7, "2_2010_0000")
TextBox2 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
confirmation2.Show
End Sub
Code:
Private Sub UserForm_Initialize()
Dim Dline As Integer
Dline = Range("SYNTHESE_AUTRES!B20000").End(xlUp).Row
TextBox7.Value = "2_2010_" & Format(Dline, "0000")
TextBox2.Value = Date
ComboBox1.ColumnCount = 1
ComboBox2.ColumnCount = 1
ComboBox3.ColumnCount = 1
ComboBox4.ColumnCount = 1
With ThisWorkbook.Worksheets("UF (2)")
ComboBox1.AddItem "Sélectionez votre service"
ComboBox2.AddItem "Sélectionez le type de transport"
ComboBox3.AddItem "Sélectionez le lieu de RDV"
ComboBox4.AddItem "Sélectionez le motif de votre transport"
For i = 4 To .Range("D65536").End(xlUp).Row
autresdemandes.ComboBox1.AddItem .Range("D" & i).Value
Next i
End With
With ThisWorkbook.Worksheets("TYPE DU TRANSPORTS")
For i = 3 To .Range("C65536").End(xlUp).Row
autresdemandes.ComboBox2.AddItem .Range("C" & i).Value
Next i
End With
With ThisWorkbook.Worksheets("MOTIF")
For i = 3 To .Range("C65536").End(xlUp).Row
autresdemandes.ComboBox4.AddItem .Range("C" & i).Value
Next i
End With
With ThisWorkbook.Worksheets("LIEUX DE RDV")
For i = 3 To .Range("C65536").End(xlUp).Row
autresdemandes.ComboBox3.AddItem .Range("C" & i).Value
Next i
End With
ComboBox1.ListIndex = 0
ComboBox2.ListIndex = 0
ComboBox3.ListIndex = 0
ComboBox4.ListIndex = 0
x = Sheets("SYNTHESE_AUTRES").Range("B65536").End(xlUp).Row + 1
End Sub

Le code de suppréssion

Code:
Private Sub CommandButton2_Click()
Dim li As Integer, i As Integer, Derlig As Integer 'déclare la variable li (LIgne)
li = Me.ListBox1.ListIndex + 2 'définit la ligne li
With Sheets("SYNTHESE_AUTRES") 'prend en compte l'onglet "Feuil2"
For i = 2 To 15
.Cells(li, i) = ""
Next i
' Tri par ordre alphabétique des noms
Derlig = .Range("B65536").End(xlUp).Row
If Derlig > 1 Then
.Range("A2:O" & Derlig).Sort Key1:=.Range("B2"), Order1:=xlAscending
End If
End With
confirmation5.Show
End Sub

Merci pour votre aide. Je sais ça va vous poser probléme le fait qu'il n'y est pas le fichier, mais pas de solution pour le déposer.

Cijoint.fr - Service gratuit de dépôt de fichiers

Antho
 
Dernière édition:

Banzai64

XLDnaute Accro
Re : Numérotation automatique dans Userform

bonjour
Une solution pour éviter les doublons
Private Sub UserForm_Initialize()
Dim Dline As Integer
Dline = Range("SYNTHESE_TRANSPORTPATIENT!B20000").End(xlUp).Row
If Dline > 2 Then ' Au moins une ligne avant
Dline = Val(Right(Sheets("SYNTHESE_TRANSPORTPATIENT").Cells(Dline, 2), 4)) + 1
End If

numérodemande.Value = "1_2010_" & Format(Dline, "0000")
datedemande.Value = Date
ComboBow1.ColumnCount = 1
ComboBox2.ColumnCount = 1
ComboBox3.ColumnCount = 1
ComboBox4.ColumnCount = 1
With ThisWorkbook.Worksheets("UF (2)")
ComboBow1.AddItem "Sélectionez votre service"
ComboBox2.AddItem "Sélectionez le mode de transport"
ComboBox3.AddItem "Sélectionez le lieu de RDV"
ComboBox4.AddItem "Sélectionez le motif de votre transport"
For i = 4 To .Range("D65536").End(xlUp).Row
transportpatient.ComboBow1.AddItem .Range("D" & i).Value
Next i
End With
With ThisWorkbook.Worksheets("MODE DE TRANSPORTS")
For i = 3 To .Range("C65536").End(xlUp).Row
transportpatient.ComboBox2.AddItem .Range("C" & i).Value
Next i
End With
With ThisWorkbook.Worksheets("MOTIF")
For i = 3 To .Range("C65536").End(xlUp).Row
transportpatient.ComboBox4.AddItem .Range("C" & i).Value
Next i
End With
With ThisWorkbook.Worksheets("LIEUX DE RDV")
For i = 3 To .Range("C65536").End(xlUp).Row
transportpatient.ComboBox3.AddItem .Range("C" & i).Value
Next i
End With
ComboBow1.ListIndex = 0
ComboBox2.ListIndex = 0
ComboBox3.ListIndex = 0
ComboBox4.ListIndex = 0
x = Sheets("SYNTHESE_TRANSPORTPATIENT").Range("B65536").End(xlUp).Row + 1
End Sub
 

Statistiques des forums

Discussions
311 723
Messages
2 081 934
Membres
101 844
dernier inscrit
pktla