B
billQ
Hello, I have a sub which copies a formula to 14 columns. Each column
formula has a calculated range above the cell where the formula is placed.
The declaration of the formula is as follows.
Public Function TotalWorkTime(unit As Long, rgnAdd As String) As Double
'here i try to set a new range to the address of rgnAdd
Set rgn2 = Range( rgn )
The routine which copies the formula into the desired cells is
dim rangeAddress as string
For x = 3 To 16
Set rgn = Range(Cells(rowFrom, x), Cells(rowTo, x))
rangeAddress = rgn.Address(RowAbsolute:=False, ColumnAbsolute:=False)
Cells(rowOnUnitsPage - 2, x).Formula = "=TotalWorkTime(" _
& unit & "," & rangeAddress & ")"
Next x
With the above code the formula in the formula bar is correct and the range
adjusts whenever I insert or delete a row. Unfortunately, I get a #Value
error in the cell. When debugging, I noticed the value of rgnAdd is missing
when the program enters the TotalWorkTime function. Therefore rgn2 is never
set and the sub is exited without execution.
If I send the function rgnAdd like the following
Cells(rowOnUnitsPage - 2, x).Formula = "=TotalWorkTime(" _
& unit & "," & Chr(34) & rangeAddress & Chr(34) & ")"
I get the correct value calculated but the range will not change as I insert
or delete rows.
Any thoughts would be greatly appreciated
thanks.
billQ
formula has a calculated range above the cell where the formula is placed.
The declaration of the formula is as follows.
Public Function TotalWorkTime(unit As Long, rgnAdd As String) As Double
'here i try to set a new range to the address of rgnAdd
Set rgn2 = Range( rgn )
The routine which copies the formula into the desired cells is
dim rangeAddress as string
For x = 3 To 16
Set rgn = Range(Cells(rowFrom, x), Cells(rowTo, x))
rangeAddress = rgn.Address(RowAbsolute:=False, ColumnAbsolute:=False)
Cells(rowOnUnitsPage - 2, x).Formula = "=TotalWorkTime(" _
& unit & "," & rangeAddress & ")"
Next x
With the above code the formula in the formula bar is correct and the range
adjusts whenever I insert or delete a row. Unfortunately, I get a #Value
error in the cell. When debugging, I noticed the value of rgnAdd is missing
when the program enters the TotalWorkTime function. Therefore rgn2 is never
set and the sub is exited without execution.
If I send the function rgnAdd like the following
Cells(rowOnUnitsPage - 2, x).Formula = "=TotalWorkTime(" _
& unit & "," & Chr(34) & rangeAddress & Chr(34) & ")"
I get the correct value calculated but the range will not change as I insert
or delete rows.
Any thoughts would be greatly appreciated
thanks.
billQ