1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Option Explicit
Sub ExportChoix()
Dim wsBase As Worksheet
Dim wsChoix As Worksheet
Dim lastRowBase As Long, lastRowChoix As Long, i As Long, j As Long
' Spécifier les feuilles de calcul
Set wsBase = ThisWorkbook.Sheets("Base")
Set wsChoix = ThisWorkbook.Sheets("Choix")
' Trouver la dernière ligne dans la colonne O de la feuille "Base"
lastRowBase = wsBase.Cells(wsBase.Rows.count, "O").End(xlUp).Row
Application.ScreenUpdating = False
' Supprimer les lignes de A5 à la dernière ligne dans les colonnes A à AB
wsChoix.Range("A5:AB" & lastRowBase).Delete
' Réinitialiser le compteur de lignes pour la feuille "Choix"
lastRowChoix = 5
' Parcourir la colonne "O" à partir de la ligne 5 jusqu'à la dernière ligne de la feuille "Base"
For i = 5 To lastRowBase
' Vérifier si la valeur dans la colonne "O" est égale à 0, 1, 2, 3, 4, 5 ou 6
If wsBase.Cells(i, "O").Value >= "1" And wsBase.Cells(i, "O").Value <= "7" Then
' Copier la plage de cellules de A:O dans la feuille "Base" vers la feuille "Choix"
wsBase.Range("A" & i & ":O" & i).Copy Destination:=wsChoix.Range("A" & lastRowChoix)
lastRowChoix = lastRowChoix + 1 ' Incrémenter le compteur de lignes pour la feuille "Choix"
End If
Next i
' Si aucune ligne n'est copiée, afficher un message
If lastRowChoix = 5 Then
MsgBox "Aucun choix n'a été effectué.", vbInformation
Else
MsgBox "Export de " & (lastRowChoix - 5) & " choix effectué.", vbInformation
End If
Application.ScreenUpdating = True
AppliquerFormule_Choix
End Sub |
Partager