Récupérer valeur dans formule - VBA
Le
François
Bonjour à tous,
Dans le bout de code ci joint, dans le deuxième If à la fin, Excel calcule
la bonne valeur mais je n'arrive pas à l'intégrer dans la formule
"=sumproduct.". Il me renvoie toujours à une erreur. Quelqu'un aurait il
une idée ?
Je vous remercie.
François
Excel 2003, W - XP
Sub CalculCharges()
Dim Cel As Range
Dim DatetD As Range
Dim Derl, Col As Long
Sheets("Mensu").Activate
Derl = [A65536].End(xlUp).Row
'Base Fillon
Fil_HorsFil = Sheets("Bdd_Taux").Range("M9")
Fil_SmicHo = Sheets("Bdd_Taux").Range("M7")
Fil_CoefMax = Sheets("Bdd_Taux").Range("M8")
'Mois de Novembre
For Each Cel In Range("I4:I" & Derl)
DateD = [I1]
If DateD >= Cells(Cel.Row, 6) And (DateD <= Cells(Cel.Row, 7) Or
Cells(Cel.Row, 7) = "") Then
'Mutuelle NC
Cells(Cel.Row, 10) = "=sumproduct((St_MUT_NC=D" & Cel.Row & ")*(H" &
Cel.Row & "*Tx_Mut_NC))"
'Prévoyance NC
Cells(Cel.Row, 11) = "=sumproduct((St_Prev_NC=D" & Cel.Row & ")*(H"
& Cel.Row & "*Tx_Prev_NC))"
'URSSAF Maladie
Cells(Cel.Row, 12) = "=sumproduct((St_UR_Mal=D" & Cel.Row & ")*(H" &
Cel.Row & "*Tx_UR_Mal))"
'URSSAF Vieillesse
Cells(Cel.Row, 13) = "=sumproduct((St_UR_Vieil=D" & Cel.Row & ")*(H"
& Cel.Row & "*Tx_UR_Vieil))"
'URSSAF Prev
Cells(Cel.Row, 14) = "=sumproduct((St_UR_Prev=D" & Cel.Row & ")*(H"
& Cel.Row & "*Tx_UR_Prev))"
'ASSEDIC Chomage
Cells(Cel.Row, 16) = "=sumproduct((St_AS_Cho=D" & Cel.Row & ")*(H" &
Cel.Row & "*Tx_AS_Cho))"
If Cells(Cel.Row, 8) / Cells(Cel.Row, 5) < Fil_HorsFil Then
'URSSAF Fillon
'ici Fillon = "((Fil_CoefMax / 0.6) * ((1.6 * Fil_SmicHo * "
& Cells(Cel.Row, 5) & " / " & Cells(Cel.Row, 8) & ") - 1))"
'ici Coef = ((Fil_CoefMax / 0.6) * ((1.6 * Fil_SmicHo *
Cells(Cel.Row, 5).Value / Cells(Cel.Row, 8).Value) - 1))
If Coef < 0.26 Then
=> 'Cells(Cel.Row, 15) = "=sumproduct((St_UR_Fil=D" &
Cel.Row & ")*(H" & Cel.Row & "*((Fil_CoefMax/0.6)*((1.6*Fil_SmicHo*E" &
Cel.Row & "/H" & Cel.Row & ")-1))))"
ou => Cells(Cel.Row, 15) = "=sumproduct((St_UR_Fil=D" &
Cel.Row & ")*(H" & Cel.Row & "*((Fil_CoefMax / 0,6) * ((1,6 * Fil_SmicHo *"
& Cells(Cel.Row, 5).Value & "/" & Cells(Cel.Row, 8).Value & ") - 1))))"
Fillon = ""
End If
End If
Dans le bout de code ci joint, dans le deuxième If à la fin, Excel calcule
la bonne valeur mais je n'arrive pas à l'intégrer dans la formule
"=sumproduct.". Il me renvoie toujours à une erreur. Quelqu'un aurait il
une idée ?
Je vous remercie.
François
Excel 2003, W - XP
Sub CalculCharges()
Dim Cel As Range
Dim DatetD As Range
Dim Derl, Col As Long
Sheets("Mensu").Activate
Derl = [A65536].End(xlUp).Row
'Base Fillon
Fil_HorsFil = Sheets("Bdd_Taux").Range("M9")
Fil_SmicHo = Sheets("Bdd_Taux").Range("M7")
Fil_CoefMax = Sheets("Bdd_Taux").Range("M8")
'Mois de Novembre
For Each Cel In Range("I4:I" & Derl)
DateD = [I1]
If DateD >= Cells(Cel.Row, 6) And (DateD <= Cells(Cel.Row, 7) Or
Cells(Cel.Row, 7) = "") Then
'Mutuelle NC
Cells(Cel.Row, 10) = "=sumproduct((St_MUT_NC=D" & Cel.Row & ")*(H" &
Cel.Row & "*Tx_Mut_NC))"
'Prévoyance NC
Cells(Cel.Row, 11) = "=sumproduct((St_Prev_NC=D" & Cel.Row & ")*(H"
& Cel.Row & "*Tx_Prev_NC))"
'URSSAF Maladie
Cells(Cel.Row, 12) = "=sumproduct((St_UR_Mal=D" & Cel.Row & ")*(H" &
Cel.Row & "*Tx_UR_Mal))"
'URSSAF Vieillesse
Cells(Cel.Row, 13) = "=sumproduct((St_UR_Vieil=D" & Cel.Row & ")*(H"
& Cel.Row & "*Tx_UR_Vieil))"
'URSSAF Prev
Cells(Cel.Row, 14) = "=sumproduct((St_UR_Prev=D" & Cel.Row & ")*(H"
& Cel.Row & "*Tx_UR_Prev))"
'ASSEDIC Chomage
Cells(Cel.Row, 16) = "=sumproduct((St_AS_Cho=D" & Cel.Row & ")*(H" &
Cel.Row & "*Tx_AS_Cho))"
If Cells(Cel.Row, 8) / Cells(Cel.Row, 5) < Fil_HorsFil Then
'URSSAF Fillon
'ici Fillon = "((Fil_CoefMax / 0.6) * ((1.6 * Fil_SmicHo * "
& Cells(Cel.Row, 5) & " / " & Cells(Cel.Row, 8) & ") - 1))"
'ici Coef = ((Fil_CoefMax / 0.6) * ((1.6 * Fil_SmicHo *
Cells(Cel.Row, 5).Value / Cells(Cel.Row, 8).Value) - 1))
If Coef < 0.26 Then
=> 'Cells(Cel.Row, 15) = "=sumproduct((St_UR_Fil=D" &
Cel.Row & ")*(H" & Cel.Row & "*((Fil_CoefMax/0.6)*((1.6*Fil_SmicHo*E" &
Cel.Row & "/H" & Cel.Row & ")-1))))"
ou => Cells(Cel.Row, 15) = "=sumproduct((St_UR_Fil=D" &
Cel.Row & ")*(H" & Cel.Row & "*((Fil_CoefMax / 0,6) * ((1,6 * Fil_SmicHo *"
& Cells(Cel.Row, 5).Value & "/" & Cells(Cel.Row, 8).Value & ") - 1))))"
Fillon = ""
End If
End If

Poser une question


Si tu veux récupérer la valeur dans la cellule au lieu de la formule, écris
:
Cells(Cel.Row, 15) = Evaluate("=sumproduct((St_UR_Fil=D" & _
Cel.Row & ")*(H" & Cel.Row & "*((Fil_CoefMax/0.6)*((1.6*Fil_SmicHo*E" & _
Cel.Row & "/H" & Cel.Row & ")-1))))")
Pour ce qui est de :
Fillon = ""
je t'en laisse l'entière paternité ;-))
Cordialement.
Daniel
"François"
Merci pour votre réponse.
Pour bien comprendre, pourquoi ne puis je pas écrire :
Cells(Cel.Row, 15) = ("=sumproduct((St_UR_Fil=D" & Cel.Row & ")*(H" &
Cel.Row & "*" & coef &"))" pour avoir le détails du calcul dans la cellule.
Est ce lié au nombre avec une virgule dans Excel ? Autre ???
Merci encore.
Cordialement,
François
"Daniel"
utilise ta syntaxe; si tu veux la valeur, utilise la mienne. Ou est-ce qu'il
y a un problème dans la formule ?
Daniel
"François"
Aussi, je faisais la calcul du Coef pour pouvoir le réutiliser
ultérieurement.
Donc, lorsque que je saisis la fonction "sumproduct", je souhaite qu'il
récupère la valeur du Coef et qu'elle apparaisse dans la cellule. J'ai
essayais Coef.value, mais rien !
Merci.
François
"Daniel" eRYX%
Cel.Row & ")*(H" & Cel.Row & "*Coef)))"
ne fonctionne pas car la formule contient le mot Coef qui est une variable
VBA et qui n'est pas reconnu par Excel.
Par contre
Cells(Cel.Row, 15) = evaluate("=sumproduct((St_UR_Fil=D" & _
Cel.Row & ")*(H" & Cel.Row & "*Coef)))")
est parfaitement licite.
Tu pourrais attribuer le nom "Coef" à un nom excel (ThisWorkbook.Names.Add
"Coef", Visible = 2)
et le définir ainsi :
[Coef]=...
en modifiant :
Cells(Cel.Row, 15) = evaluate("=sumproduct((St_UR_Fil=D" & _
Cel.Row & ")*(H" & Cel.Row & "*range(Coef))))")
Daniel
"François"