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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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
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,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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