Salut Maverick,
Eriiic
Géniale, UNION !
Pour tout avouer, j'étais parti sur le même type de boucle mais avec l'idée HIDDEN=True , DELETE, HIDDEN=False sur les lignes concernées quand j'ai vu ta réponse. Brillant... et j'utilise UNION tous les jours!
Bref, je phagocyte l'idée de tes neurones et l'adapte à ma boucle, en te remerciant beaucoup.
@Maverick
- démarrage de la macro d'un double-clic sur [A1] ;
- une InputBox te demande les références des blocs à éliminer START/STEP/ROWS/END
Chaque référence doit être séparée du caractère "/" sans espace.
Attention! Pas de sécurité installée! Travaille comme un pro!
* START : première ligne à traiter ;
* STEP : le pas entre les blocs ;
* ROWS : nombre de lignes à éliminer ;
* END : l'ensemble du fichier = 0 sinon tu tapes le n° de la première ligne à CONSERVER pour, éventuellement, garder le reste du fichier intact.
Ex: 2/5/3/0
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'
Dim tSplit, rCells As Range
Cancel = True
Application.ScreenUpdating = False
'
If Not Intersect(Target, Range("A1")) Is Nothing Then
sRep = Application.InputBox("Veuillez encoder : START/STEP/ROWS/END", "Suppression de lignes")
If Len(sRep) > 6 Then
tSplit = Split(sRep, "/")
iStart = CInt(tSplit(0))
iStep = CInt(tSplit(1))
iRows = CInt(tSplit(2))
lEnd = IIf(tSplit(3) = "0", UsedRange.Rows.Count, CLng(tSplit(3)) - 1)
Set rCells = Rows(UsedRange.Rows.Count + 1)
For x = iStart To lEnd Step iStep
Set rCells = Union(rCells, Rows(x).Resize(IIf(lEnd = UsedRange.Rows.Count, iRows, IIf(x + iRows - 1 < lEnd, iRows, lEnd - x+1)), 1).EntireRow)
Next
End If
rCells.Delete
End If
'
Application.ScreenUpdating = True
'
End Sub
A+
Ben, oui, condenser, j'aime ça...
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'
Dim rCells As Range
Cancel = True
'
sRep = Application.InputBox("Veuillez encoder : START/STEP/ROWS/END", "Suppression de lignes")
If Len(sRep) < 7 Then Exit Sub
iRows = CInt(Split(sRep, "/")(2))
lEnd = IIf(Split(sRep, "/")(3) = "0", UsedRange.Rows.Count, CLng(Split(sRep, "/")(3)) - 1)
'
Set rCells = Rows(UsedRange.Rows.Count + 1).EntireRow
For x = CInt(Split(sRep, "/")(0)) To lEnd Step CInt(Split(sRep, "/")(1))
Set rCells = Union(rCells, Rows(x).Resize(IIf(lEnd = UsedRange.Rows.Count, iRows, IIf(x + iRows - 1 < lEnd, iRows, lEnd - x + 1)), 1).EntireRow)
Next
rCells.Delete
'
End Sub