Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default User Function Not Recalculating

Excel 2003

I've created a simple user function in VBA. It uses data in a cell to
calculate an answer. It works fine, except when I change the input data,
the function doesn't recalculate. All other recalcs work on the
spreadsheet.

I have checked that auto recalc is on, and but even when I press F9, the
recalc doesn't work. I have to edit the cell formula or copy and paste the
formulae again in order to recalc.

Any thoughts on resolving this?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default User Function Not Recalculating

Place the following line at the beginning of your function

Application.Volatile
--
Kevin Backmann


"ZootRot" wrote:

Excel 2003

I've created a simple user function in VBA. It uses data in a cell to
calculate an answer. It works fine, except when I change the input data,
the function doesn't recalculate. All other recalcs work on the
spreadsheet.

I have checked that auto recalc is on, and but even when I press F9, the
recalc doesn't work. I have to edit the cell formula or copy and paste the
formulae again in order to recalc.

Any thoughts on resolving this?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default User Function Not Recalculating

Look he

http://xldynamic.com/source/xld.xlFAQ0024.html

under the UDF heading.

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"ZootRot" wrote in message ...
| Excel 2003
|
| I've created a simple user function in VBA. It uses data in a cell to
| calculate an answer. It works fine, except when I change the input data,
| the function doesn't recalculate. All other recalcs work on the
| spreadsheet.
|
| I have checked that auto recalc is on, and but even when I press F9, the
| recalc doesn't work. I have to edit the cell formula or copy and paste the
| formulae again in order to recalc.
|
| Any thoughts on resolving this?
|
|


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default User Function Not Recalculating

to get Excel to recalculate it, put all precedent cells in the argument to
the function

instead of

Public function Mysum()
Dim tot as Double, cell as Range
for each cell in Range("A1:A10")
if isnumeric(cell) then
tot = tot + cell.Value
end if
Next
Mysum = tot
End Function

do

Public function Mysum(rng as range)
dim tot as Double, cell as Range
for each cell in rng
if isnumeric(cell) then
tot = tot + cell.Value
end if
Next
Mysum = tot
End Function

usage =MySum(A1:A10)

then it will recalculate when a cell in A1:A10 is changed.

--
Regards,
Tom Ogilvy

"ZootRot" wrote:

Excel 2003

I've created a simple user function in VBA. It uses data in a cell to
calculate an answer. It works fine, except when I change the input data,
the function doesn't recalculate. All other recalcs work on the
spreadsheet.

I have checked that auto recalc is on, and but even when I press F9, the
recalc doesn't work. I have to edit the cell formula or copy and paste the
formulae again in order to recalc.

Any thoughts on resolving this?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default User Function Not Recalculating

You could add "application.volatile" and the UDF will recalc the next time that
excel recalcs.

But if you change something that the function needs but doesn't cause a
recalculation, your UDF could be incorrect.

If possible, it's better to pass the cells that the UDF needs to use so that
excel can know when to calculate that function.

function myFunc(rng1 as range, rng2 as range)
myfunc = rng1.value + rng2.value
end function

is better than:

function myFunc(rng1 as range)
myfunc = rng1.value + rng1.offset(0,1).value
end function



ZootRot wrote:

Excel 2003

I've created a simple user function in VBA. It uses data in a cell to
calculate an answer. It works fine, except when I change the input data,
the function doesn't recalculate. All other recalcs work on the
spreadsheet.

I have checked that auto recalc is on, and but even when I press F9, the
recalc doesn't work. I have to edit the cell formula or copy and paste the
formulae again in order to recalc.

Any thoughts on resolving this?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default User Function Not Recalculating

Ps. There are some changes that won't cause the function to recalculate -- even
if you pass all the ranges.

Things like formatting changes (font/fill/boldness...) have this trouble. You'd
want to use application.volatile, but force a recalc before you trust the
results.

ZootRot wrote:

Excel 2003

I've created a simple user function in VBA. It uses data in a cell to
calculate an answer. It works fine, except when I change the input data,
the function doesn't recalculate. All other recalcs work on the
spreadsheet.

I have checked that auto recalc is on, and but even when I press F9, the
recalc doesn't work. I have to edit the cell formula or copy and paste the
formulae again in order to recalc.

Any thoughts on resolving this?


--

Dave Peterson
Reply
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
VBA Created Worksheet Function Not Recalculating Falcon Feet Excel Discussion (Misc queries) 5 February 26th 10 06:05 PM
recalculation not recalculating some cells containing user functio velvetlady Excel Discussion (Misc queries) 2 January 14th 10 07:31 PM
Function isn't recalculating Chris Excel Worksheet Functions 2 May 22nd 09 09:06 AM
Using the NOW() function without it recalculating Sean C Excel Worksheet Functions 3 January 16th 06 10:52 PM
Stopping User Defined Functions for Recalculating Jim Excel Programming 4 June 6th 05 12:51 PM


All times are GMT +1. The time now is 08:03 AM.

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

About Us

"It's about Microsoft Excel"