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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| Option Explicit
Sub SuppressionDeLigne()
Dim LigneASupprimer As Long
Dim ColonneActivecell As Long
Dim LigneASupprimerMoins1 As Long
Dim LigneDebut As Long
Dim LigneFin As Long
Dim Continuer As Boolean
With ActiveSheet
.Unprotect
Continuer = True
If .Name <> "Etude" And .Name <> "Etude opt" Then
MsgBox "Seuls les onglets Etude ou Etude opt sont valides pour cette opération, fin de programme !", _
vbCritical, "Vérification du nom de l'onglet"
Continuer = False
End If
LigneDebut = RechercherLignesDebutOuFin("Deb")
LigneFin = RechercherLignesDebutOuFin("Fin")
If LigneDebut = 0 Or LigneFin = 0 Then
MsgBox "Ligne début : " & LigneDebut & ", ligne fin : " & LigneFin _
& Chr(10) & "Les limites début et fin ne sont pas fixées, fin de programme !", _
vbCritical, "Vérification des limites"
Continuer = False
End If
With ActiveCell
LigneASupprimer = .Row
ColonneActivecell = .Column
LigneASupprimerMoins1 = LigneASupprimer - 1
End With
If LigneASupprimer < LigneDebut Or LigneASupprimer > LigneFin Then
MsgBox "La ligne à supprimer est hors des limites, fin de programme !", _
vbCritical, "Contrôle de la position de la ligne à supprimer"
Continuer = False
End If
If Continuer = True Then
.Rows(LigneASupprimer).Delete Shift:=xlUp
'Remise en forme si sous chapitre
If .Range("B" & LigneASupprimerMoins1).Font.Bold = True And .Range("B" & LigneASupprimerMoins1).Interior.ColorIndex = 34 Then
MiseEnFormeLigneChapitre .Range("B" & LigneASupprimerMoins1 & ":P" & LigneASupprimerMoins1)
End If
.Cells(LigneASupprimer, ColonneActivecell).Activate
End If
.Protect , AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True
End With
End Sub
Function RechercherLignesDebutOuFin(ByVal MotRecherche As String) As Long
Dim CellRecherchee As Range
RechercherLignesDebutOuFin = 0
Set CellRecherchee = Cells.Find(What:=MotRecherche, LookIn:=xlValues)
If Not CellRecherchee Is Nothing Then RechercherLignesDebutOuFin = CellRecherchee.Row
Set CellRecherchee = Nothing
End Function
Sub MiseEnFormeLigneChapitre(ByVal AireBordure As Range)
Dim PositionBordure As Variant
Dim CtrI As Integer
With AireBordure
With .Font
.Bold = True
.ColorIndex = 3
End With
With .Interior
.ColorIndex = 34
.Pattern = xlSolid
.PatternColorIndex = 49
End With
PositionBordure = Array(xlEdgeTop, xlEdgeBottom, xlEdgeRight, xlEdgeLeft)
For CtrI = LBound(PositionBordure) To UBound(PositionBordure)
With .Borders(PositionBordure(CtrI))
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
Next CtrI
End With
AireBordure(1, 1).Font.ColorIndex = 1
End Sub |
Partager