XL 2019 Date

le___destin

XLDnaute Occasionnel
Je veux créer une colone d'un tableau lorsque je rempli la premiere case emplie automatiquement les autre cellule jusqu'à la date du fin du moi
 

danielco

XLDnaute Accro
Essaie :

VB:
Private Sub Worksheet_Calculate()
  Dim C As Range, ResC As String, Cellule As Range
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  For Each C In Range("F12", Cells(Rows.Count, 6).End(xlUp))
    If C.Offset(, -2) <> "" And C.Offset(, -2) <> ResC Then
      Debug.Print C.Address(0, 0)
      ResC = C
      If Application.CountIf(C.Resize(3), "- -") = 3 And C.Row < 27 Then
        If C.Offset(, 1).Resize(3).MergeCells = False Then
          Application.DisplayAlerts = False
          C.Offset(, 1).Resize(3, 7).Copy Cells(C.Row, 22)
          C.Offset(, 1).Resize(3, 7).Validation.Delete
          C.Offset(, 1).Resize(3, 7).MergeCells = True
          Application.DisplayAlerts = True
        End If
        GoTo Fin
      End If
      If C.Offset(, 1).Resize(3).MergeCells = True Then
        C.Offset(, 1).Resize(3, 7).MergeCells = False
        Cells(C.Row, 22).Resize(3, 7).Copy C.Offset(, 1)
      End If
      For Each Cellule In C.Resize(3)
        If Cellule.Value = "- -" Then
          Cellule.EntireRow.Hidden = True
        Else
          Cellule.EntireRow.Hidden = False
        End If
      Next Cellule
    End If
Fin:
  Next C
  Application.EnableEvents = True
  Application.ScreenUpdating = True
End Sub

Daniel
 

danielco

XLDnaute Accro
Non.

Annotation 2019-09-18 161941.png
 

danielco

XLDnaute Accro
Vérifie :

VB:
Private Sub Worksheet_Calculate()
  Dim C As Range, ResC As String, Cellule As Range, plage As Range
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  Set plage = Range("M12", Cells(Rows.Count, 13).End(xlUp)).Offset(, -7)
  Set plage = plage.Resize(plage.Count - 1)
  For Each C In Range("M12", Cells(Rows.Count, 13).End(xlUp)).Offset(, -7)
'    If C.Row = 24 Then Stop
    If C.Offset(, -2) <> "" And C.Offset(, -2) <> ResC Then
      Debug.Print C.Address(0, 0)
      ResC = C
      If Application.CountIf(C.Resize(3), "- -") = 3 And C.Row < 27 Then
        If C.Offset(, 1).Resize(3).MergeCells = False Then
          Application.DisplayAlerts = False
          C.Offset(, 1).Resize(3, 7).Copy Cells(C.Row, 22)
          C.Offset(, 1).Resize(3, 7).Validation.Delete
          C.Offset(, 1).Resize(3, 7).MergeCells = True
          [G42:M44].Copy C.Offset(, 1).Resize(3, 7)
          C.Offset(, 1).Resize(3, 7).Interior.Color = C.Interior.Color
          Application.ScreenUpdating = True
          Application.DisplayAlerts = True
        End If
        GoTo Fin
      End If
      If C.Offset(, 1).Resize(3).MergeCells = True Then
        C.Offset(, 1).Resize(3, 7).MergeCells = False
        Cells(C.Row, 22).Resize(3, 7).Copy C.Offset(, 1)
      End If
      For Each Cellule In C.Resize(3)
    
        If Cellule.Value = "- -" Then
          Cellule.EntireRow.Hidden = True
        Else
          Cellule.EntireRow.Hidden = False
          Application.ScreenUpdating = True
        End If
      Next Cellule
        
    End If
Fin:
  Next C
  Application.EnableEvents = True
  Application.ScreenUpdating = True
End Sub

Daniel
 

Pièces jointes

  • destin(2).xlsm
    44.5 KB · Affichages: 5

le___destin

XLDnaute Occasionnel
VB:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

  Dim C As Range
  If Left(Sh.Name, 4) <> "mois" Then Exit Sub
  ActiveSheet.Unprotect "0931"
  If Target.Address = "$D$11" Then
    If Not IsDate(Target(1)) Or Target.Count > 1 Then Exit Sub
    If Day(Target) <> 1 Then Exit Sub
    Application.EnableEvents = False
    [L11:L41,F11:F41].Value = 0
    [D12:D41] = ""
    Rows("12:41").Hidden = False
    With Target.Resize(DateSerial(Year(Target), Month(Target) + 1, 1) - Target)
        .NumberFormat = Target.NumberFormat
        .DataSeries
    End With
    With Application
      If .CountA([D39:D41]) < 3 Then
        Rows(41).Offset(-2 + .CountA([D39:D41])).Resize(3 - .CountA([D39:D41])).Hidden = True
      End If
    End With
    Application.EnableEvents = True
  ElseIf Not Intersect(Target, [L11:L41,F11:F41]) Is Nothing Then
    Application.EnableEvents = False
    For Each C In Intersect(Target, [L11:L41,F11:F41])
      If Application.Weekday(Cells(C.Row, 4), 2) > 5 Then
        C.Value = 0
      End If
    Next C
    Application.EnableEvents = True
    
  End If
  ActiveSheet.Protect "0931"
End Sub
 

Discussions similaires

Réponses
13
Affichages
494
Réponses
7
Affichages
311

Statistiques des forums

Discussions
312 108
Messages
2 085 361
Membres
102 874
dernier inscrit
Petro2611