Remplir toutes lignes vides d'un feuillet par UserForm

mic67

XLDnaute Junior
Bonjour à tous,
J'ai une macro pour remplir la première ligne
vide, mais si entre deux lignes écritent, une est vide
mon code passe outre et va à la dernière ligne écrite.
Je cherche à combler toutes les lignes vides avant
d'aller à la dernière vide.
Plus explications dans le fichier joint.
Merci
 

Pièces jointes

  • Lignes.xlsm
    20.3 KB · Affichages: 51

CHALET53

XLDnaute Barbatruc
Re : Remplir toutes lignes vides d'un feuillet par UserForm

bonjour,

un essai :

remplacer le code par celui-ci

Private Sub CommandButton1_Click()
Dim y As Long
Dim i As Integer, j As Integer
For i = 1 To TextBox37.Value

y = Cells(Rows.Count, 2).End(xlUp).Row + 1
For j = 4 To y
If Cells(j, 1) = "" And Cells(j, 2) = "" And Cells(j, 3) = "" And Cells(j, 4) = "" And Cells(j, 5) = "" And Cells(j, 6) = "" And Cells(j, 7) = "" Then
Cells(j, 1) = (TextBox1)
Cells(j, 2) = (TextBox2)
Cells(j, 3) = (TextBox3)
Cells(j, 4) = (TextBox38)
Cells(j, 5) = (TextBox33)
Cells(j, 6) = (TextBox34)
Cells(j, 7) = (TextBox7)
j = y
End If
Next j
Next i
Unload Me
End Sub
a+
 

Bebere

XLDnaute Barbatruc
Re : Remplir toutes lignes vides d'un feuillet par UserForm

bonjour Mic
bienvenue
avec ce code
Code:
Private Sub CommandButton1_Click()
    Dim DerL As Long, i As Integer
    Dim L As Long

    If Me.TextBox37 <> "" Then
        DerL = TextBox37.Value
        For L = 4 To DerL
            If Application.CountA(Range("A" & L & ":F" & L)) = 0 Then
                'counta équivalent de nbval
                For i = 1 To 7
                    Cells(L, i) = Me("TextBox" & i)
                Next i
                ' Cells(L, 2) = (TextBox2)
                ' Cells(L, 3) = (TextBox3)
                ' Cells(L, 4) = (TextBox4)
                ' Cells(L, 5) = (TextBox5)
                ' Cells(L, 6) = (TextBox6)
                ' Cells(L, 7) = (TextBox7)
            End If
        Next L
    Else
        MsgBox "Entrer une valeur,svp"
    End If
    ' Unload Me
End Sub
 

PrinceCorwin

XLDnaute Occasionnel
Re : Remplir toutes lignes vides d'un feuillet par UserForm

Bonjour le forum,
Chalet, Berbere,


A mon tour de donner une solution :
VB:
Option Explicit
Private Sub CommandButton1_Click()
Dim i, y, k As Integer
Dim iDerLigne, nbLigne, nbVide As Integer
iDerLigne = [A65000].End(xlUp).Row
nbVide = Application.CountIf(Range("A4:A" & iDerLigne), "")
nbLigne = 1
k = TextBox37.Value
If nbVide > 0 Then
    For i = 4 To iDerLigne
        If Cells(i, 1) = "" And nbLigne <= k Then
            Cells(i, 1) = (TextBox1)
            Cells(i, 2) = (TextBox2)
            Cells(i, 3) = (TextBox3)
            Cells(i, 4) = (TextBox38)
            Cells(i, 5) = (TextBox33)
            Cells(i, 6) = (TextBox34)
            Cells(i, 7) = (TextBox7)
            nbLigne = nbLigne + 1
        End If
    Next
End If
If nbLigne < k Then
    For i = nbLigne To k
        y = Cells(Rows.Count, 2).End(xlUp).Row + 1
        Cells(y, 1) = (TextBox1)
        Cells(y, 2) = (TextBox2)
        Cells(y, 3) = (TextBox3)
        Cells(y, 4) = (TextBox38)
        Cells(y, 5) = (TextBox33)
        Cells(y, 6) = (TextBox34)
        Cells(y, 7) = (TextBox7)
    Next i
End If
 Unload Me
 End Sub

Bonne journée
 
Dernière édition:

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
313 344
Messages
2 097 337
Membres
106 916
dernier inscrit
Soltani mohamed