VBA: Using a range in a formula

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.
 
B

Bob Phillips

Try

Sheets("hours available").Cells(ActiveCell.Row + 1,
ActiveCell.Column).Formula = "=dsum(work_items_database,""work effort
(hours)""," & row1.Address & ":" & row2.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