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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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,190,558
Messages
5,981,686
Members
439,729
Latest member
purna

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