How to refer to an object property in a formula

J

James

I wanted to creat a simple cell forumala such as:

=if(activesheet.name = "OCT03","current month","prior
month")

I get the #NAME result.

So is is possible to reference an object property directly
in a formaula rather than having to use a macro?
 
J

J.E. McGimpsey

No, XL can't directly access VBA properties. you'll have to either
use a UDF or use built-in functions.

UDF:

Public Function SheetName(rng As Range) As String
Application.Volatile
SheetName = rng.Parent.Name
End Function

call as:

=IF(SheetName(A1) = "OCT03", "current month","prior month")


Built-in:

=IF(MID(CELL("filename",A1), FIND("]", CELL("filename",A1))+1,
255)="OCT03", "current month", "prior month")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top