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 47 48 49 50 51 52 53
|
Option Explicit
Sub SupprimerDesLignesDUnTableau()
Dim DocEnCours As Document
Dim I As Long, J As Long, IndexMatrice As Long, LigneEnCours As Long
Dim MatriceDelete() As Variant
Set DocEnCours = ActiveDocument
With DocEnCours
If .Tables.Count = 0 Then Exit Sub
For J = .Tables.Count To 1 Step -1
IndexMatrice = 0
LigneEnCours = 0
With .Tables(J)
For I = 1 To .Range.Cells.Count
Select Case I
Case 1 To 10
With .Range.Cells(I)
Select Case .RowIndex
Case 5, 6
LigneEnCours = .RowIndex
Case Else
If LigneEnCours < .RowIndex Then
ReDim Preserve MatriceDelete(IndexMatrice)
MatriceDelete(IndexMatrice) = .RowIndex
IndexMatrice = IndexMatrice + 1
LigneEnCours = .RowIndex
End If
End Select
End With
Case Else
Exit For
End Select
Next I
If IndexMatrice > 0 Then
For I = .Rows.Count To 1 Step -1
For IndexMatrice = LBound(MatriceDelete) To UBound(MatriceDelete)
If I = MatriceDelete(IndexMatrice) Then
.Rows(I).Delete
Exit For
End If
Next IndexMatrice
Next I
Erase MatriceDelete
End If
End With
Next J
End With
Set DocEnCours = Nothing
End Sub |
Partager