Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to set a cell value to an equation using variables as the values. I need the cell to become a formula cell.

What I have tried:

Range(Cells(LastRow + 1, LastCol + 2)).Formula = "=SUM(cells(7,LastCol+2):cells(LastRow,LastCol+2))"
Posted
Updated 24-Feb-22 8:30am

1 solution

Try this:
VBA
Dim startCell As Range, endCell As Range, formulaCell As Range
Set startCell = ReferencedWorksheet.Cells(7, LastCol+2 )
Set endCell = ReferencedWorksheet.Cells(LastRow, LastCol+2 )
Set formulaCell = ReferencedWorksheet.Cells(LastRow + 1, LastCol + 2)
formulaCell.Formula = "=SUM(" & startCell.Address & ":" & endCell.Address & ")"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900