Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
donesquire
 
Posts: n/a
Default Force refresh of custom functions

Hi, I created a custom function using VBA in Excel. The function name is used
in a spreadsheet and (i) pulls numbers from 2 different cells, (ii) passes
them as arguments to the function, and then (iii) display a result with the
value returned by the function. However, when the values of the 2 "sources
cells" change, the result shown in the cell with the function doesn't update
automatically. Is there something I can do to force it to refresh? Any help
is appreciated.

Kind regards,
Don Thompson

  #2   Report Post  
bj
 
Posts: n/a
Default

one option would be to add
"Application.Volatile"
as a line in your function

"donesquire" wrote:

Hi, I created a custom function using VBA in Excel. The function name is used
in a spreadsheet and (i) pulls numbers from 2 different cells, (ii) passes
them as arguments to the function, and then (iii) display a result with the
value returned by the function. However, when the values of the 2 "sources
cells" change, the result shown in the cell with the function doesn't update
automatically. Is there something I can do to force it to refresh? Any help
is appreciated.

Kind regards,
Don Thompson

  #3   Report Post  
JE McGimpsey
 
Posts: n/a
Default

The best way is to include the cells as arguments to your function. So
instead of

Public Function foo()
foo = Range("A1").Value + Range("A2").Value
End Function

use

Public Function bar(arg1 As Double, arg2 As Double) As Double
bar = arg1 + arg2
End Function

then call the function with

A3: =bar(A1, A2)

Then whenever A1 or A2 changes, A3 will be updated (as long as
Calculation is set to Automatic).

Alternatively, you could make the function volatile:

Public Function foobar()
Application.Volatile
foobar = Range("A1").Value + Range("A2").Value
End Function

which will cause foobar() to recalculate each time any cell in the
worksheet is calculated.


In article ,
"donesquire" wrote:

Hi, I created a custom function using VBA in Excel. The function name is used
in a spreadsheet and (i) pulls numbers from 2 different cells, (ii) passes
them as arguments to the function, and then (iii) display a result with the
value returned by the function. However, when the values of the 2 "sources
cells" change, the result shown in the cell with the function doesn't update
automatically. Is there something I can do to force it to refresh? Any help
is appreciated.

  #4   Report Post  
donesquire
 
Posts: n/a
Default

Thank you both, these suggestions are very helpful.

Cheers,
Don

"bj" wrote:

one option would be to add
"Application.Volatile"
as a line in your function

"donesquire" wrote:

Hi, I created a custom function using VBA in Excel. The function name is used
in a spreadsheet and (i) pulls numbers from 2 different cells, (ii) passes
them as arguments to the function, and then (iii) display a result with the
value returned by the function. However, when the values of the 2 "sources
cells" change, the result shown in the cell with the function doesn't update
automatically. Is there something I can do to force it to refresh? Any help
is appreciated.

Kind regards,
Don Thompson

  #5   Report Post  
donesquire
 
Posts: n/a
Default

Thank you both, these suggestions are very helpful.

Cheers,
Don

"JE McGimpsey" wrote:

The best way is to include the cells as arguments to your function. So
instead of

Public Function foo()
foo = Range("A1").Value + Range("A2").Value
End Function

use

Public Function bar(arg1 As Double, arg2 As Double) As Double
bar = arg1 + arg2
End Function

then call the function with

A3: =bar(A1, A2)

Then whenever A1 or A2 changes, A3 will be updated (as long as
Calculation is set to Automatic).

Alternatively, you could make the function volatile:

Public Function foobar()
Application.Volatile
foobar = Range("A1").Value + Range("A2").Value
End Function

which will cause foobar() to recalculate each time any cell in the
worksheet is calculated.


In article ,
"donesquire" wrote:

Hi, I created a custom function using VBA in Excel. The function name is used
in a spreadsheet and (i) pulls numbers from 2 different cells, (ii) passes
them as arguments to the function, and then (iii) display a result with the
value returned by the function. However, when the values of the 2 "sources
cells" change, the result shown in the cell with the function doesn't update
automatically. Is there something I can do to force it to refresh? Any help
is appreciated.




  #6   Report Post  
bj
 
Posts: n/a
Default

One of the advantages to what Je says is that if you have a large program
forcing the "Volatile" function issue can dramatically increase the time for
recalcs. Most programers make a habit of using the volatile component only
when absolutely neccessary.

"donesquire" wrote:

Thank you both, these suggestions are very helpful.

Cheers,
Don

"JE McGimpsey" wrote:

The best way is to include the cells as arguments to your function. So
instead of

Public Function foo()
foo = Range("A1").Value + Range("A2").Value
End Function

use

Public Function bar(arg1 As Double, arg2 As Double) As Double
bar = arg1 + arg2
End Function

then call the function with

A3: =bar(A1, A2)

Then whenever A1 or A2 changes, A3 will be updated (as long as
Calculation is set to Automatic).

Alternatively, you could make the function volatile:

Public Function foobar()
Application.Volatile
foobar = Range("A1").Value + Range("A2").Value
End Function

which will cause foobar() to recalculate each time any cell in the
worksheet is calculated.


In article ,
"donesquire" wrote:

Hi, I created a custom function using VBA in Excel. The function name is used
in a spreadsheet and (i) pulls numbers from 2 different cells, (ii) passes
them as arguments to the function, and then (iii) display a result with the
value returned by the function. However, when the values of the 2 "sources
cells" change, the result shown in the cell with the function doesn't update
automatically. Is there something I can do to force it to refresh? Any help
is appreciated.


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
Keep custom format in new worksheet Buddy Excel Discussion (Misc queries) 2 March 14th 05 10:03 AM
3 questions about automated c++ com add-in worksheet functions gert Excel Worksheet Functions 0 March 10th 05 09:57 AM
custom functions stop working in PivotTable in Excel2003 Mike Melnikov Excel Discussion (Misc queries) 0 February 10th 05 12:38 PM
Custom Functions scott Excel Worksheet Functions 2 December 28th 04 12:23 AM
Custom Type Charts Problem Reetesh B. Chhatpar Excel Worksheet Functions 0 November 23rd 04 10:55 AM


All times are GMT +1. The time now is 09:58 PM.

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"