lignes vides si conditions formulaire non remplies

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:

Discussions similaires

Réponses
6
Affichages
202
Réponses
16
Affichages
544

Statistiques des forums

Discussions
311 709
Messages
2 081 756
Membres
101 812
dernier inscrit
trufu