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
|
Public bout1 As Object
Public bout2 As Object
Sub ajoutdansbarre()
Application.CommandBars("cell").Reset
Dim MyMenu As Object
Set MyMenu = Application.ShortcutMenus(xlWorksheetCell).MenuItems.AddMenu("Planification", 1)
With MyMenu.MenuItems
'ajout "nom du bouton",macro associée, , emplacement du bouton,
Set bout1 = .Add("Planifier", "fusion_ou_pas", , 1, "")
Set bout2 = .Add("Déplanifier", "fusion_ou_pas", , 2, , "")
End With
Set MyMenu = Nothing
End Sub
Sub fusion_ou_pas()
If Selection.Rows.Count > 1 Then
MsgBox "Veuillez selectionner les heures sur une seule ligne SVP"
Exit Sub
End If
ligneautorisée = "7:8:14:15:21:22"
If InStr(ligneautorisée, Selection.Row) > 0 Then
Select Case CommandBars.ActionControl.Caption
Case "Planifier"
Selection.MergeCells = True
Selection.Interior.Color = vbGreen
Selection.Borders.LineStyle = xlContinuous
'Selection.Borders(xlInsideVertical).LineStyle = xlNone
'Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Case "Déplanifier"
Selection.Value = ""
Selection.Interior.Color = xlNone
Selection.MergeCells = False
Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
Selection.Borders.LineStyle = xlContinuous
End Select
End If
marque_les_heures_debut_fin
End Sub
Sub marque_les_heures_debut_fin()
heures = Array(1, 1, "06:00", "06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", _
"14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", _
"23:00", "23:30", "00:00", "00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00")
lig = Selection.Row
debut = ""
oldadresse = ""
fin = ""
temps = 0
With Sheets(1)
For col = 2 To .Range("ax1").Column + 2
If InStr(Cells(lig, col).MergeArea.Address, ":") > 0 And oldadresse <> Cells(lig, col).MergeArea.Address Then
oldadresse = Cells(lig, col).MergeArea.Address
If debut = "" Then debut = heures(Range(Split(Cells(lig, col).MergeArea.Address, ":")(0)).Column)
fin = heures(Range(Split(Cells(lig, col).MergeArea.Address, ":")(1)).Column + 1)
temps = temps + Range(Cells(lig, col).MergeArea.Address).Columns.Count / 2
End If
Next
Range("ba" & lig) = temps
Range("ay" & lig) = debut
Range("az" & lig) = fin
End With
End Sub |
Partager