Microsoft 365 Macro ne fonctionne pas automatiquement

al1gsxr

XLDnaute Nouveau
Bonjour,

Je me suis perdu dans mon fichier car à l'origine, la macro fonctionnait automatiquement et maintenant je dois entrer manuellement la condition dans la cellule pour que la macro s'exécute.

Cette perdition est du au fait que je cherchais à la faire fonctionner malgré avoir la feuille protégée.

J'ai des colonnes qui doivent se masquer une fois un horaire dépassé .

En attente de votre aide.

PS:Je ne peux pas le joindre car trop volumineux donc je me permet de mettre mon code ci-dessous.

Private Sub Workbook_AfterOpen()

Call StartClock

End Sub

Private Sub Workbook_Open()

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("I309")) Is Nothing Then

Select Case Target.Value

Case 1

Columns("H:M").EntireColumn.Hidden = True

Case 2

Range("H:M").EntireColumn.Hidden = True

Case 3

Range("H:T").EntireColumn.Hidden = True

Case 4

Range("H:Z").EntireColumn.Hidden = True

Case 5

Columns("H:AF").EntireColumn.Hidden = True

Case 0

Range("O:Q").EntireColumn.Hidden = False

Range("U:W").EntireColumn.Hidden = False

Range("AA:AC").EntireColumn.Hidden = False

End Select

End If

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Call StopClock

End Sub

Cdlt
 

fanfan38

XLDnaute Barbatruc
Bonjour
dans le haut de la boite de message il y a un signe </> pour mettre les codes
les lignes ci dessous je comprends pas
Private Sub Workbook_Open()
Private Sub Worksheet_Change(ByVal Target As Range)

Au vu de ton code si tu saisi un chiffre en I309 la macro se fait
je ne vois rien qui remplirait automatiquement cette cellule
A+ François
 

al1gsxr

XLDnaute Nouveau
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("N309")) Is Nothing Then
   Select Case Target.Value
           Case 1
           Columns("H:N").EntireColumn.Hidden = True
           Case 2
           Range("H:N").EntireColumn.Hidden = True
           Case 3
           Range("H:T").EntireColumn.Hidden = True
           Case 4
           Range("H:Z").EntireColumn.Hidden = True
           Case 5
           Columns("H:AF").EntireColumn.Hidden = True
           Case 6
           Range("H:AL").EntireColumn.Hidden = True
           Case 7
           Range("H:AR").EntireColumn.Hidden = True
           Case 8
           Range("H:AX").EntireColumn.Hidden = True
           Case 9
           Range("H:BD").EntireColumn.Hidden = True
           Case 10
           Range("H:BJ").EntireColumn.Hidden = True
           Case 11
           Range("H:BP").EntireColumn.Hidden = True
           Case 12
           Range("H:CB").EntireColumn.Hidden = True
           Case 13
           Range("H:CH").EntireColumn.Hidden = True
           Case 14
           Range("H:CN").EntireColumn.Hidden = True
           Case 15
           Range("H:CT").EntireColumn.Hidden = True
           Case 16
           Range("H:CZ").EntireColumn.Hidden = True
           Case 17
           Range("H:DF").EntireColumn.Hidden = True
           Case 18
           Range("H:DL").EntireColumn.Hidden = True
           Case 19
           Range("H:DR").EntireColumn.Hidden = True
           Case 20
           Range("H:DX").EntireColumn.Hidden = True
           Case 21
           Range("H:ED").EntireColumn.Hidden = True
           Case 22
           Range("H:EJ").EntireColumn.Hidden = True
           Case 23
           Range("H:EP").EntireColumn.Hidden = True
           Case 24
           Range("H:EV").EntireColumn.Hidden = True
           Case 25
           Range("H:FB").EntireColumn.Hidden = True
           Case 26
           Range("H:FH").EntireColumn.Hidden = True
           Case 27
           Range("H:FN").EntireColumn.Hidden = True
           Case 28
           Range("H:FT").EntireColumn.Hidden = True
           Case 29
           Range("H:FZ").EntireColumn.Hidden = True
           Case 30
           Range("H:GF").EntireColumn.Hidden = True
           Case 31
           Range("H:GL").EntireColumn.Hidden = True
           Case 32
           Range("H:GR").EntireColumn.Hidden = True
           Case 33
           Range("H:GX").EntireColumn.Hidden = True
           Case 34
           Range("H:HD").EntireColumn.Hidden = True
           Case 35
           Range("H:HJ").EntireColumn.Hidden = True
           Case 36
           Range("H:HP").EntireColumn.Hidden = True
           Case 37
           Range("H:HV").EntireColumn.Hidden = True
           Case 38
           Range("H:IB").EntireColumn.Hidden = True
           Case 39
           Range("H:IH").EntireColumn.Hidden = True
           Case 40
           Range("H:IN").EntireColumn.Hidden = True
           Case 41
           Range("H:IT").EntireColumn.Hidden = True
           Case 42
           Range("H:IZ").EntireColumn.Hidden = True
           Case 43
           Range("H:JF").EntireColumn.Hidden = True
           Case 44
           Range("H:JL").EntireColumn.Hidden = True
           Case 45
           Range("H:JR").EntireColumn.Hidden = True
           Case 46
           Range("H:JX").EntireColumn.Hidden = True
           Case 47
           Range("H:KD").EntireColumn.Hidden = True
           Case 48
           Range("H:KJ").EntireColumn.Hidden = True
           Case 49
           Range("H:KP").EntireColumn.Hidden = True
           Case 50
           Range("H:KV").EntireColumn.Hidden = True
           Case 51
           Range("H:LB").EntireColumn.Hidden = True
           Case 52
           Columns("H:LH").EntireColumn.Hidden = True
           Case 53
           Range("H:LN").EntireColumn.Hidden = True
           Case 54
           Range("H:LT").EntireColumn.Hidden = True
           Case 55
           Range("H:LZ").EntireColumn.Hidden = True
           Case 56
           Range("H:MF").EntireColumn.Hidden = True
           Case 57
           Range("H:ML").EntireColumn.Hidden = True
           Case 58
           Range("H:MR").EntireColumn.Hidden = True
           Case 59
           Range("H:MX").EntireColumn.Hidden = True
           Case 60
           Range("H:ND").EntireColumn.Hidden = True
           Case 61
           Range("H:NJ").EntireColumn.Hidden = True
           Case 62
           Range("H:NP").EntireColumn.Hidden = True
           Case 63
           Range("H:NV").EntireColumn.Hidden = True
           Case 64
           Range("H:OB").EntireColumn.Hidden = True
           Case 65
           Range("H:OH").EntireColumn.Hidden = True
           Case 66
           Range("H:ON").EntireColumn.Hidden = True
           Case 67
           Range("H:OT").EntireColumn.Hidden = True
           Case 68
           Range("H:OZ").EntireColumn.Hidden = True
           Case 69
           Range("H:PF").EntireColumn.Hidden = True
           Case 70
           Range("H:PL").EntireColumn.Hidden = True
           Case 71
           Range("H:PR").EntireColumn.Hidden = True
           Case 72
           Range("H:PX").EntireColumn.Hidden = True
           Case 73
           Range("H:QD").EntireColumn.Hidden = True
           Case 74
           Range("H:QJ").EntireColumn.Hidden = True
           Case 75
           Range("H:QP").EntireColumn.Hidden = True
           Case 76
           Range("H:QV").EntireColumn.Hidden = True
           Case 77
           Range("H:RB").EntireColumn.Hidden = True
           Case 78
           Range("H:RH").EntireColumn.Hidden = True
           Case 79
           Range("H:RN").EntireColumn.Hidden = True
           Case 80
           Range("H:RT").EntireColumn.Hidden = True
           Case 81
           Range("H:RZ").EntireColumn.Hidden = True
           Case 82
           Range("H:SF").EntireColumn.Hidden = True
           Case 83
           Range("H:SL").EntireColumn.Hidden = True
           Case 84
           Range("H:SR").EntireColumn.Hidden = True
           Case 85
           Range("H:SX").EntireColumn.Hidden = True
           Case 86
           Range("H:TD").EntireColumn.Hidden = True
           Case 87
           Range("H:TJ").EntireColumn.Hidden = True
           Case 88
           Range("H:TP").EntireColumn.Hidden = True
           Case 89
           Range("H:TV").EntireColumn.Hidden = True
           Case 90
           Range("H:UB").EntireColumn.Hidden = True
           Case 91
           Range("H:UH").EntireColumn.Hidden = True
           Case 92
           Range("H:UN").EntireColumn.Hidden = True
           Case 93
           Range("H:UT").EntireColumn.Hidden = True
           Case 94
           Range("H:UZ").EntireColumn.Hidden = True
       Case 0
           Range("O:VO").EntireColumn.Hidden = False
   End Select
End If
End Sub
 

al1gsxr

XLDnaute Nouveau
J'ai ajouté les codes, que dois-fournir de plus ?....Le fichier est trop volumineux je ne peux pas le joindre....
Mon seul problème est que le code fourni fonctionne uniquement si c'est moi qui met le chiffre en N309 et qui appuie sur "enter", si le chiffre se met seul il ne se passe rien.
 

al1gsxr

XLDnaute Nouveau
VB:
Option Explicit
Dim NextTick

Sub StartClock()
    UpdateClock
End Sub

Sub StopClock()
'   Cancels the OnTime event (stops the clock)
    On Error Resume Next
    Application.OnTime NextTick, "UpdateClock", , False
End Sub

Sub cbClockType_Click()
'   Hides or unhids the clock
    With ThisWorkbook.Sheets("071220")
        If .DrawingObjects("cbClockType").Value = xlOn Then
            .ChartObjects("ClockChart").Visible = True
        Else
            .ChartObjects("ClockChart").Visible = False
        End If
    End With
End Sub

Sub UpdateClock()
'   Updates the clock that's visible
    Dim Clock As Chart
    Set Clock = ThisWorkbook.Sheets("071220").ChartObjects("ClockChart").Chart
    
    If Clock.Parent.Visible Then
'       ANALOG CLOCK
        Const PI As Double = 3.14159265358979
        Dim CurrentSeries As Series
        Dim s As Series
        Dim x(1 To 2) As Variant
        Dim v(1 To 2) As Variant
    
'       Hour hand
        Set CurrentSeries = Clock.SeriesCollection("HourHand")
        x(1) = 0
        x(2) = 0.5 * Sin((Hour(Time) + (Minute(Time) / 60)) * (2 * PI / 12))
        v(1) = 0
        v(2) = 0.5 * Cos((Hour(Time) + (Minute(Time) / 60)) * (2 * PI / 12))
        CurrentSeries.XValues = x
        CurrentSeries.Values = v
        
'       Minute hand
        Set CurrentSeries = Clock.SeriesCollection("MinuteHand")
        x(1) = 0
        x(2) = 0.8 * Sin((Minute(Time) + (Second(Time) / 60)) * (2 * PI / 60))
        v(1) = 0
        v(2) = 0.8 * Cos((Minute(Time) + (Second(Time) / 60)) * (2 * PI / 60))
        CurrentSeries.XValues = x
        CurrentSeries.Values = v
    
'       Second hand
        Set CurrentSeries = Clock.SeriesCollection("SecondHand")
        x(1) = 0
        x(2) = 0.85 * Sin(Second(Time) * (2 * PI / 60))
        v(1) = 0
        v(2) = 0.85 * Cos(Second(Time) * (2 * PI / 60))
        CurrentSeries.XValues = x
        CurrentSeries.Values = v
    Else
'       DIGITAL CLOCK
        ThisWorkbook.Sheets("071220").Range("DigitalClock").Value = CDbl(Time)
    End If
    
'   Set up the next event one second from now
    NextTick = Now + TimeValue("00:00:01")
    Application.OnTime NextTick, "UpdateClock"
    'Feuil2.idcolumm()
    
    'Dim currenttarget As Range
    'Set currenttarget = ThisWorkbook.Sheets("180121").Range("N309")
    'ThisWorkbook.Sheets("180121").idcolumm (currenttarget)
    
    
End Sub
 

al1gsxr

XLDnaute Nouveau
Nous avons trouvé de notre côté, merci François.
Autre question, comment pourrais-je protéger une feuille tout en maintenant une macro active qui s'active toutes les 10 mn ?.....je parle du premier partage de code que j'ai fourni sur ce poste, le code s'active toutes les dix minutes grâce à l'horloge
 

fanfan38

XLDnaute Barbatruc
Bonjour
en début de macro juste après: Private Sub Worksheet_Change(ByVal Target As Range)
mettre la ligne si dessous
Sheets("Feuil1").Unprotect Password:="Mot de Passe"
en fin de macro avant le end sub mettre
Sheets("Feuil1").Protect Password:="Mot de Passe", AllowFiltering:=True

Changer si nécessaire le nom de la feuille et le mot de passe

A+ François
 

Discussions similaires

Statistiques des forums

Discussions
314 633
Messages
2 111 416
Membres
111 126
dernier inscrit
vitam