Declaring a simple function

mtheriault2000

Well-known Member
Joined
Oct 23, 2008
Messages
826
Hello

First time that i want to declare a simple function and no success.

I want B_Body to be a function, so i can use it in other calculation. So each time i need the B_Body value, program will call the calculation

Code:
Public B_Body, B_OPen, B_Close as variant
 
Function B_Body() 
   B_Body = B_Open - B_Close
End Function

Martin
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
VBA isn't like certain other programming languages (C for example) so there's no need to declare your function in addition to providing the function definition - you just need the function body. So you just need code in your module like:

Code:
Public B_OPen, B_Close
 
Function B_Body() 
   B_Body = B_Open - B_Close
End Function
where B_Open and B_Close are global variant variables.
 
Upvote 0

mtheriault2000

Well-known Member
Joined
Oct 23, 2008
Messages
826
Re:(resolve) Declaring a simple function

Thank you Richard.

Solution: Don't declare the B_Body as a variant.

Resolve

Martin
 
Upvote 0

Forum statistics

Threads
1,191,175
Messages
5,985,111
Members
439,940
Latest member
Kyrad42

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
Top