Function calling a sub procedure

akhendre88

Board Regular
Joined
Sep 17, 2015
Messages
76
Hello,

I am writing a function which call the sub procedure to calculate the area. Below is code.
Code:
Function GET_AREA(Length As Double, Width As Variant)
    area Length, Width
End Function

Sub area(l As Double, w As Variant)
     MsgBox l * w
End Sub

It is working fine. How can I do it if I want to return a result in any cell instead of MsgBox.

Thank you.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hello,

I am writing a function which call the sub procedure to calculate the area. Below is code.
Code:
Function GET_AREA(Length As Double, Width As Variant)
    area Length, Width
End Function

Sub area(l As Double, w As Variant)
     MsgBox l * w
End Sub

It is working fine. How can I do it if I want to return a result in any cell instead of MsgBox.
You would not use a Sub to do that, rather, you would have your function do all the work...
Code:
Function GET_AREA(Length As Double, Width As Double) As Double
  GET_AREA = Length * Width
End Function
Then you would put this formula in the cell you wanted the result in (here, I am assuming the Length is in cell A1 and the Width is in cell B1)...

=GET_AREA(A1,B1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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