Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Using user-defined functions in cells

What is the correct way to define a function that can be plugged
into any spreadsheet cell as a formula??

I defined a function as follows:

Public Function DoMyStuff ()
importantData = Sheet1.Range("A1").Value
importantData = importantData * 10
DoMyStuff = importantData ' Return a value
End Function

I then plugged my function into cell "B1" as follows:

=DoMyStuf()

Okay, now I noticed that when anybody edits the
contents of cell "A1" that my "DoMyStuff" is not getting
called again. Do I need some code in my "DoMyStuff"
function to detect if the contents of cell "A1" changed??

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Using user-defined functions in cells

Generally you want to make your inputs parameters of your UDF.
If they are not, your function won't recalculate when the inputs change (as
you saw).

Public Function DoMyStuff (rngIn)
DoMyStuff = rngIn * 10 ' Return a value
End Function

=DoMyStuf(A1)

Tim

"Robert Crandal" wrote in message
...
What is the correct way to define a function that can be plugged
into any spreadsheet cell as a formula??

I defined a function as follows:

Public Function DoMyStuff ()
importantData = Sheet1.Range("A1").Value
importantData = importantData * 10
DoMyStuff = importantData ' Return a value
End Function

I then plugged my function into cell "B1" as follows:

=DoMyStuf()

Okay, now I noticed that when anybody edits the contents of cell "A1" that
my "DoMyStuff" is not getting
called again. Do I need some code in my "DoMyStuff"
function to detect if the contents of cell "A1" changed??

Thank you!




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
Getting #VALUE in cells with User Defined Functions MikeZz Excel Programming 2 September 27th 08 06:28 AM
Using User-Defined Functions in Cells Trent Argante[_2_] Excel Programming 0 June 13th 07 03:54 PM
Using User-Defined Functions in Cells NickHK[_3_] Excel Programming 2 June 13th 07 03:36 PM
Using User-Defined Functions in Cells Dave Peterson Excel Programming 0 June 13th 07 03:11 PM
User Defined Functions - Help Text - Make it Easy for the User Andibevan[_2_] Excel Programming 4 March 17th 05 09:51 AM


All times are GMT +1. The time now is 03:11 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"