PC Review


Reply
Thread Tools Rate Thread

custom function - finding cell address

 
 
extrnh
Guest
Posts: n/a
 
      27th Nov 2010
i have a custom function that returns an array of values based on
several inputs. to implement this, a range of cells are highlighted,
the function is typed, and then ctrl + shift + enter keys are
entered. i would like to calculate the number of cells that are
required for the output so the user does not have to input this.
cannot use activecell, that only works when the function is created.
if the any of the arguments point to a cell, the function is
recaclulated when that cell changes. the activecell is then the
argument cell and not the cell that is being calculated. is it
possible to find what cell is being calculated during the
recalculation process?
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      27th Nov 2010
I am not sure, exactly what you need, but maybe this can help you:

Selection.Cells.Count
Selection.address

Maybe you should post your code for further comments.

Per

On 27 Nov., 02:38, extrnh <ext...@yahoo.com> wrote:
> i have a custom function that returns an array of values based on
> several inputs. *to implement this, a range of cells are highlighted,
> the function is typed, and then ctrl + shift + enter keys are
> entered. *i would like to calculate the number of cells that are
> required for the output so the user does not have to input this.
> cannot use activecell, that only works when the function is created.
> if the any of the arguments point to a cell, the function is
> recaclulated when that cell changes. *the activecell is then the
> argument cell and not the cell that is being calculated. *is it
> possible to find what cell is being calculated during the
> recalculation process?


 
Reply With Quote
 
extrnh
Guest
Posts: n/a
 
      30th Nov 2010
On Nov 26, 8:38*pm, extrnh <ext...@yahoo.com> wrote:
> i have a custom function that returns an array of values based on
> several inputs. *to implement this, a range of cells are highlighted,
> the function is typed, and then ctrl + shift + enter keys are
> entered. *i would like to calculate the number of cells that are
> required for the output so the user does not have to input this.
> cannot use activecell, that only works when the function is created.
> if the any of the arguments point to a cell, the function is
> recaclulated when that cell changes. *the activecell is then the
> argument cell and not the cell that is being calculated. *is it
> possible to find what cell is being calculated during the
> recalculation process?


Here is the code;

Public Function samplefunction(N As Long, A As Double, B As Double, G
As Double, _
D As Double, P As Long) As Variant()

' execute the samplefunction function and return the output as
column array

Dim dblX() As Double
Dim i As Long
Dim lngIerr As Long
Dim varTemp As Variant
'
ReDim dblX(0 To N - 1)
On Error Resume Next
Call samplefunction_vba(N, dblX(0), A, B, G, D, P, lngIerr)
If lngIerr <> 0 Then ' error in dll - fill in output array with
error value
ReDim varTemp(1 To 1)
varTemp(1) = lngIerr
Else
ReDim varTemp(1 To N)
For i = 1 To N
varTemp(i) = dblX(i - 1)
Next i
End If
samplefunction = Application.Transpose(varTemp)

End Function


Again this is a custom function that returns an array of values. So a
FormulaArray is used when entering the function on the worksheet. N
is the number of cells in the output, which is the number of cells
that are highlighted when the FormulaArray is entered. I do not want
to require the user to input N, I want to be able to determine the
number of cells for the FormulaArray. Any ideas?
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      30th Nov 2010
Application.caller will return the range of cells that contain the formula.

If you use a multi-cell range (say A1:C9) and use an array formula like:

=myfunc(x99)
and array enter it, you could use:

Option Explicit
Function myFunc(rng As Range) As Variant

Dim HowManyRows As Long
Dim HowManyCols As Long

HowManyCols = Application.Caller.Columns.Count
HowManyRows = Application.Caller.Rows.Count

'some tests to see how to rearrange your output.
myfunc = ...

End Function



On 11/26/2010 19:38, extrnh wrote:
> i have a custom function that returns an array of values based on
> several inputs. to implement this, a range of cells are highlighted,
> the function is typed, and then ctrl + shift + enter keys are
> entered. i would like to calculate the number of cells that are
> required for the output so the user does not have to input this.
> cannot use activecell, that only works when the function is created.
> if the any of the arguments point to a cell, the function is
> recaclulated when that cell changes. the activecell is then the
> argument cell and not the cell that is being calculated. is it
> possible to find what cell is being calculated during the
> recalculation process?


--
Dave Peterson
 
Reply With Quote
 
extrnh
Guest
Posts: n/a
 
      7th Dec 2010
On Nov 30, 7:45*am, Dave Peterson <peter...@XSPAMverizon.net> wrote:
> Application.caller will return the range of cells that contain the formula.
>
> If you use a multi-cell range (say A1:C9) and use an array formula like:
>
> =myfunc(x99)
> and array enter it, you could use:
>
> Option Explicit
> Function myFunc(rng As Range) As Variant
>
> * * *Dim HowManyRows As Long
> * * *Dim HowManyCols As Long
>
> * * *HowManyCols = Application.Caller.Columns.Count
> * * *HowManyRows = Application.Caller.Rows.Count
>
> * * *'some tests to see how to rearrange your output.
> * * *myfunc = ...
>
> End Function
>
> On 11/26/2010 19:38,extrnhwrote:
>
> > i have a custom function that returns an array of values based on
> > several inputs. *to implement this, a range of cells are highlighted,
> > the function is typed, and then ctrl + shift + enter keys are
> > entered. *i would like to calculate the number of cells that are
> > required for the output so the user does not have to input this.
> > cannot use activecell, that only works when the function is created.
> > if the any of the arguments point to a cell, the function is
> > recaclulated when that cell changes. *the activecell is then the
> > argument cell and not the cell that is being calculated. *is it
> > possible to find what cell is being calculated during the
> > recalculation process?

>
> --
> Dave Peterson


Dave:

Thank you very much, this is what I needed.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the Address of a Cell tb Microsoft Excel Worksheet Functions 5 13th Dec 2007 01:59 PM
creating custom function - need to receive a cell address as a par =?Utf-8?B?TWFyayBWSUk=?= Microsoft Excel Programming 5 29th Sep 2006 08:06 PM
Finding cell address... korcutt Microsoft Excel Programming 2 7th Nov 2005 10:50 PM
Finding Cell Address Faisal Microsoft Excel Worksheet Functions 7 6th Oct 2004 07:56 AM
Re: finding cell address Alan Beban Microsoft Excel Misc 0 16th Sep 2004 11:13 PM


Features
 

Advertising
 

Newsgroups
 


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