Retrieving Macro Values

jdresie

New Member
Joined
Jan 13, 2005
Messages
2
This question probably has an easy answer, but I can't find it in the help.

I have a Visual Basic macro function that does some non-standard
calculations. I have it written as a function so I could got into any cell and
type its name and inputs (ie. =cheat(...)). However, there is only one value
I want out of the macro, and I don't know how to get that value as the
result in the cell.

I think the mathematics etc. are okay in the macro, but I don't know the
command that specifies the out put! Please help

Thanks
J
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
If your function is defined as:

Function Cheat(x as integer, y as integer)

Then you set the function name equal to the value you want. So, for example, if you want to return the value of z, you would use:

Cheat = z
End Function

Does this help?

Mike.
 
Upvote 0
You just set the function's value to whatever you're returning.

Code:
Function Cheat(varInput as Variant) as Double
    ' math, math, math
    Cheat = (whatever you came up with)
End Function
 
Upvote 0

Forum statistics

Threads
1,226,498
Messages
6,191,377
Members
453,655
Latest member
lasvegasbuffet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top