Sory but i don't know why your macro ruin my formula for example in C7 C8 C9, and why you use cell G37
If i - cell.Row >= 20 Then
Range("G37") = 20
Else
Range("G37") = i - cell.Row
End If
Macro can not use cell G37, Cell G37 is only change average. If Cell G37=20 then average for each stock is for 20 last day so that cell can not be changed. Maybe this way:
1) Macro copy cell B39: to the end,
2) next paste to G37
3) Macro run solver
4) result from J31 copy to the cell B39
5) loop (cell B40, B41 etc) loop stop when meet empty cell.
Sub Makro1()
'
' Makro1 Makro
'
'
Range("B39").Select
Selection.Copy
Range("G37").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
SolverOk SetCell:="$C$20", MaxMinVal:=1, ValueOf:="0", ByChange:="$C$11:$AG$11"
SolverSolve UserFinish:=True
Range("J31").Select
Selection.Copy
Range("C39").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Something like that but with loop. New file beacuse i added new row.
I modifed your code
Sub Makro1()
i = Range("B" & Rows.Count).End(xlUp).Row
For Each cell In Range("B39:B" & i)
cell.Copy
Range("G37").PasteSpecial Paste:=xlPasteValues
SolverOk SetCell:="$C$20", MaxMinVal:=1, ValueOf:="0", ByChange:="$C$11:$AG$11"
SolverSolve UserFinish:=True
Range("J31").Copy
cell.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
Next
Application.CutCopyMode = False
End Sub
WORKS!
BIG THANKS ALF. I am very very happy and appreciate your help and support big thanks again
Bookmarks