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
| Sub Dispatching()
Dim LastLig As Long, i As Long, j As Long
Dim N As Integer, DD As Integer, DF As Integer
Dim Tb
With ThisWorkbook.Worksheets("Staffing request Mgt")
LastLig = .Cells(.Rows.Count, 1).End(xlUp).Row
Tb = .Range("A5:D" & LastLig)
End With
With Feuil1
.UsedRange.Offset(1).Clear
If LastLig > 4 Then
j = 4
For i = 1 To LastLig - 4
DD = Col(CDate(Tb(i, 3)))
DF = Col(CDate(Tb(i, 4)), True)
.Range("A" & j) = Tb(i, 1)
.Range("B" & j) = Tb(i, 2)
.Range(.Cells(j, DD), .Cells(j, DF)).Interior.ColorIndex = 48
j = j + 1
Next i
If j > 4 Then
N = .Cells(3, .Columns.Count).End(xlToLeft).Column
Tri .Range(.Cells(4, 1), .Cells(j - 1, N))
End If
End If
End With
End Sub
'Permet de connaître la colonne correspondant à la date
'PS: Aucun creux ne doit être présent entre les dates de la ligne 3
Private Function Col(ByVal D As Date, Optional Fin As Boolean) As Integer
Dim LastCol As Integer, Diff As Integer
Dim Dm As Date
With Feuil1
LastCol = .Cells(3, .Columns.Count).End(xlToLeft).Column
If LastCol > 2 Then
Dm = CDate(.Range("C3").Value)
Diff = DateDiff("d", Dm, D)
Col = 3 + IIf(Diff > 0, Diff, 0)
If Fin Then Col = Application.Min(LastCol, 3 + IIf(Diff > 0, Diff, 0))
End If
End With
End Function
'Permet le tri de la feuille Rest
Private Sub Tri(ByVal Rng As Range)
Dim Ws As Worksheet
Set Ws = Rng.Worksheet
With Ws
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Rng(1, 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.SetRange Rng
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
Set Ws = Nothing
End Sub |
Partager