Private Sub CommandButton1_Click()
Dim ShtCopie As Worksheet, ShtVers As Worksheet
Dim Zone As Range, NextLig As Long
' Définir les variables objet des feuilles
'Set ShtCopie = ActiveSheet
Set ShtCopie = ThisWorkbook.Sheets("feuille 2")
Set ShtVers = ThisWorkbook.Sheets("feuille 1")
' Définir la variable objet de la zone
Set Zone = ShtVers.Range("C5:C11,C13,C16:C23")
' Trouver la prochaine ligne vide
NextLig = LigneVide(Zone)
' Si la ligne a été trouvée <> 0
If NextLig <> 0 Then
' On fait un copier/coller valeur
ShtCopie.Range("B3:F3").Copy
ShtVers.Range("C" & NextLig).PasteSpecial Paste:=xlPasteValues
End If
' Effacer les variables objet
Set ShtCopie = Nothing: Set ShtVers = Nothing: Set Zone = Nothing
End Sub
Function LigneVide(Rng As Range)
Dim Cel As Range
LigneVide = 0
For Each Cel In Rng
If Cel.Value = "" Then
LigneVide = Cel.Row
Exit Function
End If
Next Cel
MsgBox "Toutes les lignes sont remplies !"
End Function
'Private Sub CommandButton1_Click()
'Dim copie As Worksheet, vers As Worksheet, derligne As Long
'Set copie = ActiveSheet
'Set vers = ThisWorkbook.Sheets("feuille 1")
'copie.Range("b3, c3, d3, e3, f3").Copy vers.Range("c" & vers.Rows.Count).End(xlUp)(2)
'End Sub
Private Sub CommandButton1_Click()
Dim ShtCopie As Worksheet, ShtVers As Worksheet
Dim Zone As Range, NextLig As Long
' Définir les variables objet des feuilles
'Set ShtCopie = ActiveSheet
Set ShtCopie = ThisWorkbook.Sheets("feuille 2")
Set ShtVers = ThisWorkbook.Sheets("feuille 1")
' Définir la variable objet de la zone
Set Zone = ShtVers.Range("C5:c33") ' code modifié Bruno66 pour essais
'Set Zone = ShtVers.Range("C5:C11,C13,C16:C23") code de Bruno45
' Trouver la prochaine ligne vide
NextLig = LigneVide(Zone)
' Si la ligne a été trouvée <> 0
If NextLig <> 0 Then
' On fait un copier/coller valeur
ShtCopie.Range("B3:F3").Copy
ShtVers.Range("C" & NextLig).PasteSpecial Paste:=xlPasteValues
End If
' Effacer les variables objet
Set ShtCopie = Nothing: Set ShtVers = Nothing: Set Zone = Nothing
End Sub
Function LigneVide(Rng As Range)
Dim Cel As Range
LigneVide = 0
For Each Cel In Rng
If Cel.Value = "" Then
LigneVide = Cel.Row
Exit Function
End If
Next Cel
MsgBox "Toutes les lignes sont remplies !"
End Function
Private Sub CommandButton1_Click()
Dim i&, j&, k&, l&, t, w(), saute(), Plg1 As Range, Plg2 As Range, Fl As Worksheet
'============================================= PARAMETRES =============================================
Set Plg1 = Me.Range("B3:F3") 'Plage à copier
Set Plg2 = Me.Range("B8:F8") 'Plage de contrôle
Set Fl = Feuil2 'Feuille de destination
saute = Array("FERMETURE HEBDO*", "SOLDE FIN DE MOIS*", "TOTAL SEMAINE*") 'Lignes à sauter.
'(Les lignes commençant par "FERMETURE HEBDO", "SOLDE FIN DE MOIS", "TOTAL SEMAINE" seront ignorées.)
'======================================================================================================
Plg2.ClearContents
l = UBound(saute)
w = Plg1.Value
k = Plg1.Columns.Count
With Fl
For i = 3 To .Rows.Count
t = .Cells(i, 1).Value
For j = 0 To l
If t Like saute(j) Then Exit For
Next
If j > l Then
For j = 3 To 2 + k
If Not IsEmpty(.Cells(i, j)) Then Exit For
Next
If j > 2 + k Then
.Cells(i, 3).Resize(, k).Value = w
Plg2.Value = w
Exit For
End If
End If
Next
End With
End Sub
Private Sub CommandButton1_Click()
Dim ShtCopie As Worksheet, ShtVers As Worksheet
Dim DLig As Long, NextLig As Long, Zone As Range
' Définir les variables objet des feuilles
'Set ShtCopie = ActiveSheet
Set ShtCopie = ThisWorkbook.Sheets("feuille 2")
Set ShtVers = ThisWorkbook.Sheets("feuille 1")
' Récupérer le numéro de la dernière ligne de la feuille
DLig = ShtVers.Range("A" & Rows.Count).End(xlUp).Row
' Définir la variable objet de la zone
Set Zone = ShtVers.Range("C5:C" & DLig)
' Trouver la prochaine ligne vide
NextLig = LigneVide(Zone)
' Si la ligne a été trouvée <> 0
If NextLig <> 0 Then
' On fait un copier/coller valeur
ShtCopie.Range("B3:F3").Copy
ShtVers.Range("C" & NextLig).PasteSpecial Paste:=xlPasteValues
End If
' Effacer les variables objet
Set ShtCopie = Nothing: Set ShtVers = Nothing: Set Zone = Nothing
End Sub
Function LigneVide(Rng As Range)
Dim Cel As Range
LigneVide = 0
' En cas d'erreur on continue le code
On Error Resume Next
' Pour chaque ligne de la zone
For Each Cel In Rng
' Comme les lignes : FERMETURE HEBDO / SOLDE FIN DE MOIS / TOTAL SEMAINE
' contiennent des formules, elles ne sont donc pas vide
' Si la cellule est vide
If Cel.Value = "" Then
' Si elle contient #REF! un erreur est produite <> 0
If Err.Number = 0 Then
LigneVide = Cel.Row
Exit Function
End If
End If
' Effacer l'erreur
Err.Clear
Next Cel
' Remettre la gestion des erreurs
On Error GoTo 0
MsgBox "Toutes les lignes sont remplies !"
End Function