LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Custom formula

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use a formula in custom autofilter andy62 Excel Worksheet Functions 6 April 24th 23 09:01 PM
custom field with custom formula in pivot table! Sedaghat Nejad Excel Worksheet Functions 2 June 21st 09 11:19 AM
custom add formula Kelly******** Excel Worksheet Functions 7 January 13th 08 08:10 AM
Need Custom format, not a formula nastech Excel Discussion (Misc queries) 21 April 29th 06 03:42 AM
Custom defined formula billQ Excel Programming 2 July 15th 03 08:44 AM


All times are GMT +1. The time now is 12:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"