ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA: Using a range in a formula (https://www.excelbanter.com/excel-programming/415503-vba-using-range-formula.html)

Jayne22

VBA: Using a range in a formula
 
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.


Bob Phillips[_3_]

Using a range in a formula
 
Try

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


--
__________________________________
HTH

Bob

"Jayne22" wrote in message
...
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.





All times are GMT +1. The time now is 01:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com