lignes vides si conditions formulaire non remplies

  • Initiateur de la discussion Initiateur de la discussion rom1z
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

rom1z

XLDnaute Nouveau
Bonjour à tous, je débute en VBA et je bloque sur un problème de création de ligne vide dans un tableau.

je m'explique:

Dans la feuille "Saisie mission" je clique sur le bouton saisie
mon formulaire s'ouvre, je le rempli et ce formulaire envoie les données sur deux feuilles différentes "Saisie mission" et "missions"
l'une prend toutes les données et l'autre ne prend que certaines données et empêche les doublons afin de n'avoir qu'une ligne par Mission

j'ai donc ajouté des conditions pour éviter les doublons mais lorsque que mes données sont en doublon une ligne vide apparaît dans le tableau de ma feuille "Missions"
ce que je veux éviter car le formulaire va me générer beaucoup de doublons et donc de lignes vides...

Mon classeur est trop volumineux pour être posté mais voici le code de mon formulaire, j'espère que cela suffira...
merci !



VB:
Private Sub CommandButton1_Click()
If TextBox1 = "" Or TextBox1 = "jj/mm/aaaa" Or TextBox2 = "" Or TextBox2 = "jj/mm/aaaa" Or TextBox3 = "" Or TextBox4 = "" Or TextBox7 = "" Or ComboBox1 = "" Then
MsgBox ("Eh non ! T'as pas tout rempli !")

    Else

    If Sheets("SAISIE MISSION").Range("A4") = "" Then
    Sheets("SAISIE MISSION").Range("A4") = TextBox7
    
    Else
    Sheets("SAISIE MISSION").ListObjects("Tableau1").ListRows.Add
    End If
    
    
                    dlt = Sheets("SAISIE MISSION").Range("d1048576").End(xlUp).Row
                    
                    
                    'If Sheets("MISSIONS").Range("A" & ttl) = ComboBox1 And Sheets("MISSIONS").Range("C" & ttl) = TextBox1 Then
                    
                    
                    
                    Sheets("SAISIE MISSION").Range("A" & dlt) = ComboBox1
                    Sheets("SAISIE MISSION").Range("C" & dlt) = TextBox7
                    TextBox1 = Format(TextBox1, "mm/dd/yyyy")
                    Sheets("SAISIE MISSION").Range("D" & dlt) = TextBox1.Value
                    TextBox2 = Format(TextBox2, "mm/dd/yyyy")
                    Sheets("SAISIE MISSION").Range("E" & dlt) = TextBox2.Value
                    Sheets("SAISIE MISSION").Range("F" & dlt) = TextBox3
                    Sheets("SAISIE MISSION").Range("G" & dlt) = TextBox4
    
    If Sheets("MISSIONS").Range("A3") = "" Then
    Sheets("MISSIONS").Range("A3") = ComboBox1
    
    Else
    Sheets("MISSIONS").ListObjects("Tableau9").ListRows.Add
    End If
    
    With Worksheets("MISSIONS")
            
                        
            ttl = Sheets("MISSIONS").Range("d1048576").End(xlUp).Row
        
        If Application.CountIf(Range("A3:A500"), Me.ComboBox1.Text) = 0 Then
                    
                    'Sheets("MISSIONS").ListObjects("Tableau9").ListRows.Add
                    Sheets("MISSIONS").Range("A" & ttl) = ComboBox1
                    TextBox1 = Format(TextBox1, "mm/dd/yyyy")
                    Sheets("MISSIONS").Range("C" & ttl) = TextBox1.Value
                    TextBox2 = Format(TextBox2, "mm/dd/yyyy")
                    Sheets("MISSIONS").Range("D" & ttl) = TextBox2.Value
                    Sheets("MISSIONS").Range("E" & ttl) = TextBox3
                    Sheets("MISSIONS").Range("F" & ttl) = TextBox4
                    
        ElseIf Application.CountIf(Range("C3:C500"), Me.TextBox1.Text) = 0 Then

                    'Sheets("MISSIONS").ListObjects("Tableau9").ListRows.Add
                    Sheets("MISSIONS").Range("A" & ttl) = ComboBox1
                    TextBox1 = Format(TextBox1, "mm/dd/yyyy")
                    Sheets("MISSIONS").Range("C" & ttl) = TextBox1.Value
                    TextBox2 = Format(TextBox2, "mm/dd/yyyy")
                    Sheets("MISSIONS").Range("D" & ttl) = TextBox2.Value
                    Sheets("MISSIONS").Range("E" & ttl) = TextBox3
                    Sheets("MISSIONS").Range("F" & ttl) = TextBox4
        
        
      '  If ((Application.CountIf(Range("A3:A500"), Me.ComboBox1.Text) = 1) And (Application.CountIf(Range("C3:C500"), Me.TextBox1.Text) = 0)) Then
      '  Sheets("MISSIONS").ListObjects("Tableau9").ListRows.Delete
       ' End If
        
      
 '           If Sheets("MISSIONS").Range("A3") = "" Then
  '          Sheets("MISSIONS").Range("A3") = ComboBox1
  '
  '          Else
  '          Sheets("MISSIONS").ListObjects("Tableau9").ListRows.Add
   '         End If
  '
        
  '      Sheets("MISSIONS").Range("A" & ttl) = ComboBox1
  '      TextBox1 = Format(TextBox1, "mm/dd/yyyy")
   '     Sheets("MISSIONS").Range("C" & ttl) = TextBox1.Value
   '     TextBox2 = Format(TextBox2, "mm/dd/yyyy")
   '     Sheets("MISSIONS").Range("D" & ttl) = TextBox2.Value
    '    Sheets("MISSIONS").Range("E" & ttl) = TextBox3
    '    Sheets("MISSIONS").Range("F" & ttl) = TextBox4

    'Sheets("MISSIONS").Range("A" & ttl).Select
   ' Selection.SpecialCells(xlCellTypeBlanks).Select
   ' Selection.ListObject.ListRows(2).Delete

        End If
    
   End With
    
    
    Unload UserForm1
End If
End Sub
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
410
Réponses
3
Affichages
569
Réponses
2
Affichages
371
Réponses
6
Affichages
522
Réponses
4
Affichages
439
Retour