Absolute to Relative Referencing

S

sgltaylor

Hi All,

I have the following code which inserts a sum formula in the
activecell.

Dim startRow As Integer
Dim startCell As Range, endCell As Range
startRow = 2
With ActiveCell
Set startCell = Cells(startRow, .Column - 1)
Set endCell = .Offset(0, -12)
..Formula = "=SUM( " & startCell.Address & ":" & endCell.Address & ")"

My problem is that the sum formula is created with absolute
references.
I need the formula to be created with relative references for both the
rows
and the columns.

Any ideas on how to change from absolute to relative referencing?

Thanks,

Steve
 
M

macropod

Hi sgltaylor,

..Formula = "=SUM( " & Replace(startCell.Address, "$", "") & ":" & Replace(endCell.Address, "$", "") & ")"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top