Incrémentation en VBA dans une formule

mael00

XLDnaute Nouveau
Bonjour à tous,
J'ai un problème dans la programmation en VBA.

En effet, je voudrais incrémenter une formule avec une sélection qui diffère selon une variable (variable).

Voici la partie de code:

a = Range("G2").Value
b = Range("F2").Value
variable = Cells(3 + b, 4)
Cells(3 + a, 9) = "=(1/2*R4C4+SUM(R5C4: variable)+1/2*R[12]C[-5])/R2C6"

Merci de bien vouloir m'aider.
Cordialement.
 

tototiti2008

XLDnaute Barbatruc
Re : Incrémentation en VBA dans une formule

Bonjour PierreJean,
Re,

mael00,
Je ne te faisais pas une proposition, je te posais une question...

Bon, en admettant que la réponse à ma question soit OUI, je te propose :

"=(1/2*R4C4+SUM(R5C4:R5C" & variable & ")+1/2*R[12]C[-5])/R2C6"
 

pierrejean

XLDnaute Barbatruc
Re : Incrémentation en VBA dans une formule

Re

Effectivement on avait peut-etre oublié le .formula

Vois si tu peux t'inspirer de ces 2 sub

Code:
Sub test()
a = -2
variable = [COLOR=blue]"RC15"
[/COLOR]Cells(3 + a, 9[COLOR=blue]).Formula[/COLOR] = "=(1/2*R4C4+SUM(R5C4:" & variable & ")+1/2*R[12]C[-5])/R2C6"
End Sub
Sub test1()
a = -2
variable = [COLOR=blue]15
[/COLOR]Cells(3 + a, 9).[COLOR=blue]Formula[/COLOR] = "=(1/2*R4C4+SUM(R5C4:[COLOR=blue]RC[/COLOR]" & variable & ")+1/2*R[12]C[-5])/R2C6"
End Sub
 

Discussions similaires