First off, I do apologize if it is a silly question, but I just couldn't find an answer anywhere online. I have a question to ask anyone who is familiar in changing relative formula to absolute formula using vba.
My problem right now is that, my absolute formula is determined by calculating row difference of different cell conditions of other columns (Column C) as I have input multiple formulas across a column (Column B) using vba. Hence the absolute formula that I want to achieve is unpredictable and it is constantly changing.
Set Rng = Range(Cells(2, 3), Cells(lastrow, 3))
Range("B2").Select
startb = lastrow
For b = lastrow To 2 Step -1
If Cells(b, 3) <> Cells(b - 1, 3) Then
endb = b
rowdiff = startb - endb
Cells(end, 2).Select
ActiveCell.FormulaR1C1 = "=Countif(RC[-1]:R[" & rowdiff & "]C[-1],RC[-1])"
ActiveCell.Formula = Application.ConvertFormula(Formula:=ActiveCell.Formula, fromreferencestyle:=Application.ReferenceStyle, toabsolute:=xlAbsolute)
Selection.Copy
Range(Cells(startb, 2), Cells(endb, 2)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Next b
As you guys can see that I have a code line that can convert relative formula to absolute formula straight away. Unfortunately in my COUNTIF formula, I want an absolute range (the section before the comma) but a relative criteria (in this case the RC[-1] after the comma).
Is there anything I could do to just convert a partial formula to become absolute? Or there isn't such thing? Any help and advice is greatly appreciated. Please let me know if I am doing it in a completely wrong way.
Thank you for reading and your time.
as to your very point of partially converting a formula from relative to absolute except for the last cell reference, you could use this function
whose more verbose and (possibly) clear version is:
to be used as: