Num de ligne (ou colonne) comme variable dans une fonction

Bonjour.

voici une fonction que je desire repeter sur un certain nombre de ligne:

=NB.SI(M5:V5;"CR")+C5

je desire creer un fonction CR(x) =(NB.SI(Mx:Vx;"CR")+Cx)

j'ai essaye :

x=activecell.row

function CR(x)

CR=(NB.SI(Mx:Vx;"CR")+Cx)

end function

cette fonction est incorrecte dans sa formulation.

Etant debutant en VBA ( et excel en general), quelqu'un pourrait-il me creer explicitement cette fonction a priori simple?

Merci d'avance.

Bonjour,

Voici une solution :

Sub test()
    Dim lgLig As Long
    lgLig = ActiveCell.Row
    MsgBox CR(lgLig)   ' Pour un test, j'affiche le résultat dans une fenêtre
End Sub

Function CR(lgLig As Long) As Long
    CR = Application.WorksheetFunction.CountIf(Range("M" & lgLig & ":V" & lgLig), "CR") + Range("C" & lgLig)
End Function

j'ai essayé..je saisi l'esprit du truc.

Cependant ca semble bloquer sur les ":" qui separent "M"&lgil et "V"&lgil.

7zps-forecast.xlsm (51.19 Ko)
4zps.xlsx (15.49 Ko)

Bonsoir,

Peux-tu joindre un fichier ?

Merci

Rechercher des sujets similaires à "num ligne colonne comme variable fonction"