(Solved) – How to use a variable used as a column tracker in a formula


In a code using a loop, I use a variable as a column tracker. When some conditions are met, I want to insert a formula in a specific cell, using this variable as the column of one of the cell mentioned in the formula.
I created a very similar code, but the variable “m” was a row tracker instead of a column tracker and I was successfully using the following line:

If Cells(8, n).Value = "F" Then Cells(n, 4).Formula = "=AM4-sum(D10:D" & m & ")"

I want to use this m as a column and not as a row, here is a unsuccessful attempt:

If Cells(8, n).Value = "F" Then Cells(11, n).Formula = "=AM4-SUM(Range(Cells(11, 7), Cells(11, " & m & ")))"

Can someone help me about the synthax of the 2d line in order to make it work?

Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *