'Dynamic Constraint in a Solver loop

I have to run repetitive Solvers where the constraints "offset" 13 columns to the right whenever it starst again. The problem I´m having is that the constraints need a FormulaText:="..." at the end.

Could you please help me know how I could make those constraints "dynamic", I tried to use range variables, but it seems it want only text there. To make things a bt more complicated, the constraint is the sum of two columns.

Sub Plan_RRuby()

    Dim ano As Long 
    
    Dim ofss As Integer 
    ofss = Worksheets("Por Clase").Range("L2").Value ' It´s 12
    

    Set A = Range("N5") 
    Set B = Range("L5:L7") 
    Set C = Range("M5")  
    Set D = Range("c5")
    Set E = Range("p5") 
    Set F1 = Range("r5") 
    Set F2 = Range("r6") 
    Set F3 = Range("r7") 
    
    
        For ano = 1 To 30 
        
        SolverReset
                
        SolverOk SetCell:=A, MaxMinVal:=2, ValueOf:=0, ByChange:=B, Engine:=1, EngineDesc:="GRG Nonlinear" 
                
          
        SolverAdd CellRef:=C, Relation:=2, FormulaText:="1" 
        SolverAdd CellRef:=E, Relation:=2, FormulaText:=D 
               
        SolverAdd CellRef:=F1, Relation:=1, FormulaText:="H$5+J$5"
        SolverAdd CellRef:=F2, Relation:=1, FormulaText:="H$6+J$6"
        SolverAdd CellRef:=F3, Relation:=1, FormulaText:="H$7+J$7"
        
        SolverSolve True
    
                               
                    Set A = Range(A).Offset(0, ofss)
                    Set B = Range(B).Offset(0, ofss)
                    Set C = Range(C).Offset(0, ofss)
                    
                    Set E = Range(E).Offset(0, ofss)
                    
                    Set F1 = Range(F1).Offset(0, ofss)
                    Set F2 = Range(F2).Offset(0, ofss)
                    Set F3 = Range(F3).Offset(0, ofss)                       
   
    Next ano 

End Sub

Thanks

I tryed to use variables with ranges, but it only "likes" text.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source