VBA: Using a range in a formula

  • Thread starter Thread starter Jayne22
  • Start date Start date
J

Jayne22

Is there a way to use a range that i've declared previously in the same macro?

In my example, row1 and row2 are the ranges I want to use
(work_items_database was not declared in the macro). I want to use these
ranges in a dsum formula to go from the position of row1 to the position of
row2, but this does not work:

Sheets("hours available").Cells(ActiveCell.Row + 1,
ActiveCell.Column).FormulaR1C1 = "=dsum(work_items_database,""work effort
(hours)""," & row1.Address & ":" & row2.Address & ")"

Again, row1 and row2 are ranges that I have already declared and assigned
locations to.
 
Try

Sheets("hours available").Cells(ActiveCell.Row + 1,
ActiveCell.Column).Formula = "=dsum(work_items_database,""work effort
(hours)""," & row1.Address & ":" & row2.Address & ")"
 
Back
Top