Using TabName in a formula

Gl3n

New Member
Joined
Jan 7, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I'm trying to use TabName in a formula to complete a function that takes the last populated cell in a given column range within the same sheet, regardless of the sheet name.

I have the TabName VBA simply as:
Function TabName()
TabName = ActiveSheet.Name
End Function

Inside my cell, I've tried:

=LOOKUP(2,1/(TabName(Name!$BA:$BA<>"")),(TabName(Name!$BA:$BA)))

and

=LOOKUP(2,1/(TabName!$BA:$BA<>""),TabName!$BA:$BA)

In a separate sheet where the referenced sheet name isn't dynamic I have =LOOKUP(2,1/(Database!$A:$A<>""),Database!$A:$A) which is working fine.

If there's an alternative to referencing the sheet that the formula is written in I'd be happy to learn some alternatives too!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If you are just checking the same sheet, a sheet reference should not be necessary.
If you leave off the sheet reference, it will just default/apply to the activesheet, i.e.
Excel Formula:
=LOOKUP(2,1/($BA:$BA<>""),$BA:$BA)
 
Upvote 0
Solution
Though it seems unnecessary, in order to get your original idea to work, you need to use the INDIRECT function.
You need to use that whenever dynamicalyl building a range via formula rather than typing it in directly.

That formula would look like:
Excel Formula:
=LOOKUP(2,1/(INDIRECT(tabname() & "!$BA:$BA")<>""),INDIRECT(tabname() & "!$BA:$BA"))
 
Upvote 0
Doh! I'm overcomplicating it...just for fun of course...

Thanks again for the save and for the alternative solution if I wanted to keep it unnecessarily complicated
 
Upvote 0
You are welcome.

Yes, the key thing to remember is that is you are ever dynamically building a range in an Excel formula, you need to use the "INDIRECT" functio (to let Excel know that you are actually building a range, and not just a string).
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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