Call VBA function in a cell

yinkajewole

Active Member
Joined
Nov 23, 2018
Messages
281
How can i call a vba function in the middle of a cell value in the formula bar.
for instance, if i have a function that calculate an area in vba. if i put =area(3,4) on the formula bar it gives me the result. But now, assuming I want to sum the result of two areas in a cell, how do i go about this.
This did not work =sum(area(3,4),area(6,5))
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
That should work, what happens when you try it?
 
Upvote 0
I'm sorry, I did not specify my need completely.

However, this is what I intend to do. I want to rank the cell J25 in all the sheets and this is my formula =RANK(J25,'Sheet1:Sheet10'!J25,0).
While the sheet1 is the first sheet and sheet10 is the last sheet.
What I want now is that instead of typing the sheet name myself, I wrote a VBA function that gives me the first and last sheet names.
Code:
Function FirstP()
FirstP = Application.Sheets.Item(1).Name
End Function
Function LastP()
LastP = Application.Sheets(Sheets.Count).Name
End Function

So, substituting the VBA function into the formula gives me error =RANK(J25,FirstP():LastP()!J25,0).

The reason for all of these is that there are many workbooks I want to work on but they have different Sheet names.
 
Last edited:
Upvote 0
All your functions return are strings and I'm afraid you can't use them as you have to reference sheets.
 
Upvote 0
You could try INDIRECT I suppose but I'm not sure how that would work.

Perhaps something like this.

=RANK(J25,INDIRECT(FirstP() & ":" & LastP() & "!J25"),0)
 
Upvote 0
I've had a look and found out that INDIRECT can't be used for 3D references.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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