'### Constantes à adapter ###
Const FEUILLE As String = "test" 'nom de la feuille concernée
Const CORRECTEUR As String = "am2:at14" 'adresse de la plage du coefficient correcteur
'############################
Sub CalculCoeff_pmo()
Dim S As Worksheet
Dim R As Range
Dim Source
Dim var
Dim i&
Dim j&
Dim lig&
Dim col&
Dim A$
Dim x#
On Error GoTo Erreur
Set S = Sheets(FEUILLE)
S.Activate
Set R = Range(CORRECTEUR)
Source = R
Set R = Range("c2:e" & [a65536].End(xlUp).Row & "")
var = R
For i& = 1 To UBound(var, 1)
lig& = 0
col& = 0
x# = 0
A$ = LCase(var(i&, 1)) 'jour
If var(i&, 1) <> 0 Then
For j& = 2 To UBound(Source, 2)
If A$ = LCase(Source(1, j&)) Then
col& = j&
Exit For
End If
Next j&
A$ = LCase(var(i&, 2)) 'mois
For j& = 2 To UBound(Source, 1)
If A$ = LCase(Source(j&, 1)) Then
lig& = j&
Exit For
End If
Next j&
If lig& > 0 And col& > 0 Then
var(i&, 3) = Source(lig&, col&)
End If
Else
A$ = LCase(var(i&, 2)) 'mois
For j& = 2 To UBound(Source, 1)
If A$ = LCase(Source(j&, 1)) Then
lig& = j&
Exit For
End If
Next j&
For j& = 3 To UBound(Source, 2) - 1 'moyenne
x# = x# + Source(lig&, j&)
Next j&
var(i&, 3) = x# / 5
End If
Next i&
R = var
Exit Sub
Erreur:
If Err = 9 Then
MsgBox "La feuille " & FEUILLE & " est introuvable."
Else
MsgBox "Erreur " & Err.Number & vbCrLf & Err.Description
End If
End Sub