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
| Sub Macro2()
Dim derlign As Integer
Dim colorig As Range
With Sheets("Pointage")
derlign = .Cells(.Rows.Count, 1).End(xlUp).Row
Set colorig = .Range("E7:E" & derlign)
For num = 1 To 31
num = Format(num, 0#)
With colorig.Offset(0, num)
réf = """" & Format(Range("E6").Offset(0, num).Value, "0#") & """"
Debug.Print
.Formula = "=IF( VLOOKUP($A7,INDIRECT((" & réf & ")&""!$A$5:$k$500""" & "),6,0)=$AT$3,VLOOKUP($A7,INDIRECT((" & réf & ")&""!$A$5:$k$500""" & "),7,0),"""")"
.Value = .Value
End With
Next num
With colorig.Offset(0, 33)
.FormulaR1C1 = "=nbsup(RC[-37],50)"
.Value = .Value
End With
With colorig.Offset(0, 34)
.FormulaR1C1 = "=nbsup(RC[-38],100)"
.Value = .Value
End With
Set colorig = Nothing
End With
End Sub
Public Function nbsup(mat As Variant, nat As Integer) As Integer
Dim i As Byte
Dim nbheures As Integer
nbheures = 0
If nat <> 50 And nat <> 100 Then
MsgBox "Le 2ème argument de la fonction doit être 50 ou 100"
nbsup = 99999
Exit Function
End If
For i = 1 To 31
i = Format(i, "0#")
equiv = WorksheetFunction.Match(mat, Sheets(i).Range("A5:A1000"), 0)
nbheures = nbheures + WorksheetFunction.Index(Sheets(i).Range("A5:K1000"), equiv, 8 + IIf(nat = 50, 0, 1))
Next i
nbsup = nbheures
End Function |