Functions and worksheets, passing arguments to functions?

N

newbie

I just got a book called, Excel for Chemists. But it didnt tell me
something i want to know.

I wonder if someone out there can help me?

Here is the problem, say that i have put some data into a worksheet.
A1 cell = XValues and A2 cell = YValues.


If i have a Function that takes 2 arguments below how do i write code
to pass, XValues, Yvalues to the function Deming?

Example below:
Function Deming(XValues, Yvalues)
Dim MeanX(), MeanY()
'Get number of cells to use in calculation loop
Ncells = XValues.Count
ReDim MeanX(Ncells / 2), MeanY(Ncells / 2)
N = 0

put code here......do something...

'Define the return results as an array
Deming = Array(Slope, Intercept)
End Function

I would like to ask a related question as well. To run the programs
do name the subroutines and functions as macros? Then run the macros
by using the contextual menu and select macro/run/ macro name?

Thank you in advance,
Andrew
 
N

Niek Otten

Hi Andrew,

Look here:

http://www.cpearson.com/excel/PassingAndReturningArrays.htm

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

|I just got a book called, Excel for Chemists. But it didnt tell me
| something i want to know.
|
| I wonder if someone out there can help me?
|
| Here is the problem, say that i have put some data into a worksheet.
| A1 cell = XValues and A2 cell = YValues.
|
|
| If i have a Function that takes 2 arguments below how do i write code
| to pass, XValues, Yvalues to the function Deming?
|
| Example below:
| Function Deming(XValues, Yvalues)
| Dim MeanX(), MeanY()
| 'Get number of cells to use in calculation loop
| Ncells = XValues.Count
| ReDim MeanX(Ncells / 2), MeanY(Ncells / 2)
| N = 0
|
| put code here......do something...
|
| 'Define the return results as an array
| Deming = Array(Slope, Intercept)
| End Function
|
| I would like to ask a related question as well. To run the programs
| do name the subroutines and functions as macros? Then run the macros
| by using the contextual menu and select macro/run/ macro name?
|
| Thank you in advance,
| Andrew
 
N

newbie

Niek,

Oh! thank you for your quick response to help me! I appreciate you
because my girl friend was asking me how to do this but i didnt know
how to find the information. I bought a book and searched online but
maybe i didnt use the right search string. I am new to VBA so i have a
steep learning curve.

The link you sent looks good so i will print it out and examine the
code. Again, thank you very much!

Andrew & Sayaka
 
N

Niek Otten

You're welcome!

Thanks for the feedback

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

Niek,

Oh! thank you for your quick response to help me! I appreciate you
because my girl friend was asking me how to do this but i didnt know
how to find the information. I bought a book and searched online but
maybe i didnt use the right search string. I am new to VBA so i have a
steep learning curve.

The link you sent looks good so i will print it out and examine the
code. Again, thank you very much!

Andrew & Sayaka
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top