XL 2010 Réduire la macro

Panda79360

XLDnaute Nouveau
Bonjour,

J'ai besoin d'un coup de main, je sèche complet :eek:

Comment pourrais-je réduire ma macro svp,

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
ActiveWorkbook.Unprotect
Worksheets("RAPPORT DE VISITE DE CONTROLE").Unprotect
Select Case Range("$C$36").Value
Case Is = ""
Sheets("RAPPORT DETAILLE").Visible = True
Sheets("RAPPORT DETAILLE").Range("C2,G2,C4,G4,C6,E8,G8,E12,G12,E16,B22,D22,F22,H22,B28,D28,G28,F32,E36,G36,B38,D38,B40,D40,G40,G44,G48,G56") = ""
Sheets("RAPPORT DETAILLE").Range("D58,F58,H58,F60,H60,F62,H62,F64,H64,C66,G66,C68,G68,G70 ") = ""
Sheets("RAPPORT DETAILLE").Visible = False
Sheets("RAPPORT DETAILLE (2)").Visible = True
Sheets("RAPPORT DETAILLE (2)").Range("C2,G2,C4,G4,C6,E8,G8,E12,G12,E16,B22,D22,F22,H22,B28,D28,G28,F32,E36,G36,B38,D38,B40,D40,G40,G44,G48,G56") = ""
Sheets("RAPPORT DETAILLE (2)").Range("D58,F58,H58,F60,H60,F62,H62,F64,H64,C66,G66,C68,G68,G70 ") = ""
Sheets("RAPPORT DETAILLE (2)").Visible = False
Sheets("RAPPORT DETAILLE (3)").Visible = True
Sheets("RAPPORT DETAILLE (3)").Range("C2,G2,C4,G4,C6,E8,G8,E12,G12,E16,B22,D22,F22,H22,B28,D28,G28,F32,E36,G36,B38,D38,B40,D40,G40,G44,G48,G56") = ""
Sheets("RAPPORT DETAILLE (3)").Range("D58,F58,H58,F60,H60,F62,H62,F64,H64,C66,G66,C68,G68,G70 ") = ""
Sheets("RAPPORT DETAILLE (3)").Visible = False
Merci par avance
 
Solution
Salut, comme je ne vois qu'une partie de ta macro, la mienne sera peut-être incomplète mais voilà une suggestion:

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    Dim wsNames As Variant
    Dim i As Integer

    Application.ScreenUpdating = False
    ActiveWorkbook.Unprotect
    Worksheets("RAPPORT DE VISITE DE CONTROLE").Unprotect

    If Range("$C$36").Value = "" Then
        wsNames = Array("RAPPORT DETAILLE", "RAPPORT DETAILLE (2)", "RAPPORT DETAILLE (3)")
        For i = LBound(wsNames) To UBound(wsNames)
            Set ws = Sheets(wsNames(i))
            ws.Range("C2,G2,C4,G4,C6,E8,G8,E12,G12,E16,B22,D22,F22,H22,B28,D28,G28,F32,E36,G36,B38,D38,B40,D40,G40,G44,G48,G56") = ""...

Franc58

XLDnaute Occasionnel
Salut, comme je ne vois qu'une partie de ta macro, la mienne sera peut-être incomplète mais voilà une suggestion:

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    Dim wsNames As Variant
    Dim i As Integer

    Application.ScreenUpdating = False
    ActiveWorkbook.Unprotect
    Worksheets("RAPPORT DE VISITE DE CONTROLE").Unprotect

    If Range("$C$36").Value = "" Then
        wsNames = Array("RAPPORT DETAILLE", "RAPPORT DETAILLE (2)", "RAPPORT DETAILLE (3)")
        For i = LBound(wsNames) To UBound(wsNames)
            Set ws = Sheets(wsNames(i))
            ws.Range("C2,G2,C4,G4,C6,E8,G8,E12,G12,E16,B22,D22,F22,H22,B28,D28,G28,F32,E36,G36,B38,D38,B40,D40,G40,G44,G48,G56") = ""
            ws.Range("D58,F58,H58,F60,H60,F62,H62,F64,H64,C66,G66,C68,G68,G70 ") = ""
        Next i
    End If
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 211
Messages
2 086 291
Membres
103 171
dernier inscrit
clemm