Hello everybody.
I have simple formula like:
=IF(F2<IF(SUM($F$2:F2)-SUM($G$2:$G$5000)<0,0,SUM($F$2:F2)-SUM($G$2:$G$5000)),F2,IF(SUM($F$2:F2)-SUM($G$2:$G$5000)<0,0,SUM($F$2:F2)-SUM($G$2:$G$5000)))
I am using this formula in macro code (somewhere) like:
lr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
With ws.Range("I2:I" & lr)
.Formula = "=IF(F2<IF(SUM($F$2:F2)-SUM($G$2:$G$5000)<0,0,SUM($F$2:F2)-SUM($G$2:$G$5000)),F2,IF(SUM($F$2:F2)-SUM($G$2:$G$5000)<0,0,SUM($F$2:F2)-SUM($G$2:$G$5000)))"
.Value = .Value
End With
But , I want to use dynamic "lr" (as LastRow) instead of "$G$2:$G$5000" like "$G$2:$G$ & lr" (this doesn't work)just same as "ws.Range("I2:I" & lr)" in the code.

How can it be fixed?

Thanks in advance for any reply and help.

Best regards.