Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Steve
 
Posts: n/a
Default How can I force a worsheet to recall functions.

Hi,

I have a VBA function that is invoked multiple times in Sheet2. The function
scans a column in Sheet1 and returns a single string item. If I change the
Sheet1 column data, how do I request Sheet2 to "recall" the function to
reflect the new Sheet1 data.

Thanks.

Steve


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

One way:

Include the Sheet1 column in your function's argument list. For
instance, instead of:

=MyFunc()

Public Function MyFunc() As String
Dim rCell As Range
For Each rCell In Worksheets(1).Range("A1:A10")
If Len(rCell.Text) 0 Then _
MyFunc = MyFunc & rCell.Text
Next rCell
End Function

use:

=MyFunc2(Sheet1!A1:A10)


Public Function MyFunc2(rng As Excel.Range) As String
Dim rCell As Range
For Each rCell In rng
If Len(rCell.Text) 0 Then _
MyFunc2 = MyFunc2 & rCell.Text
Next rCell
End Function

In article ,
"Steve" wrote:

I have a VBA function that is invoked multiple times in Sheet2. The function
scans a column in Sheet1 and returns a single string item. If I change the
Sheet1 column data, how do I request Sheet2 to "recall" the function to
reflect the new Sheet1 data.

  #3   Report Post  
Steve
 
Posts: n/a
Default

Thanks for response. I see what you're suggesting but I want to pass in an
integer only and have the function return the string value from a known
column of the integer row. I do not want the function caller to require
knowledge of where the string comes from.

Steve
"JE McGimpsey" wrote in message
...
One way:

Include the Sheet1 column in your function's argument list. For
instance, instead of:

=MyFunc()

Public Function MyFunc() As String
Dim rCell As Range
For Each rCell In Worksheets(1).Range("A1:A10")
If Len(rCell.Text) 0 Then _
MyFunc = MyFunc & rCell.Text
Next rCell
End Function

use:

=MyFunc2(Sheet1!A1:A10)


Public Function MyFunc2(rng As Excel.Range) As String
Dim rCell As Range
For Each rCell In rng
If Len(rCell.Text) 0 Then _
MyFunc2 = MyFunc2 & rCell.Text
Next rCell
End Function

In article ,
"Steve" wrote:

I have a VBA function that is invoked multiple times in Sheet2. The
function
scans a column in Sheet1 and returns a single string item. If I change
the
Sheet1 column data, how do I request Sheet2 to "recall" the function to
reflect the new Sheet1 data.



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
Confused about arrays and ranges in functions Llurker Excel Worksheet Functions 0 July 7th 05 05:44 AM
Default User Defined Functions - How? flycast Excel Discussion (Misc queries) 4 May 26th 05 04:26 AM
Force refresh of custom functions donesquire Excel Worksheet Functions 5 May 11th 05 07:36 PM
3 questions about automated c++ com add-in worksheet functions gert Excel Worksheet Functions 0 March 10th 05 09:57 AM
# of Functions per cell SUB-ZERO Excel Worksheet Functions 3 January 23rd 05 10:35 PM


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