Rapport de message :*
 

modifier formule dans macro

Titre du sujet : modifier formule dans macro
par jad73 le 28/05/2012 19:06:58

bonjour le forum
j'ai une macro et je voudrais inserer une formule dont les valeurs change a chaque clic de la macro.
la formule est "NB.SI($B$2:$F$41;A6)"au départ,puis a chaque clic les valeurs "2 et 41" augmente de +1 ce qui donnerais "NB.SI($B$3:$F$42;a6)",mais comment l'incrire dans la macro.elle devrais s'inscrire entre le"End With" et le "Range("A6:B54").Copy"
 
Sub Macro4()
' Macro4 - 40-Auto
Dim plg As Byte
Dim dlg As Integer, vligne As Integer
dlg = Range("L" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = True
For plg = 34 To dlg
    With Range("H" & plg & ":L" & plg)
        .Copy Range("C1")
        .ClearContents
    End With




    Range("A6:B54").Copy
    Range("C6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    With ActiveWorkbook.Worksheets("40").Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("D6:D54"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SetRange Range("C6:D54")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Calculate
    'Range("G5").Select
    vligne = Range("AD65536").End(xlUp).Row + 1
    Range("C3:G3").Copy
    Range("AD" & vligne).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Dim Cellule As Range
Dim Plage As Range

Dim i, l, c As Integer
i = 6
Set Plage = Range("C1:G1")
While IsEmpty(Range("A" & i)) = False
     For Each Cellule In Plage
      If Range(Cellule.Address).Value = Range("C" & i).Value Then
      l = Range("E" & i).Value + 8
      c = Range("F" & i).Value + 10
      Cells(c, l) = Cells(c, l) + 1
      End If
     Next Cellule
      i = i + 1
Wend
Next
Application.ScreenUpdating = False
Range("G5").Select
End Sub




merci