Sahand
Sahand

Reputation: 8360

Excel user defined function doesn't work properly when used in SUMIFS function

I have defined the function:

Function TabName()
    TabName = ActiveSheet.Name
End Function

When I type =TabName() into a cell, I get the text tabname in the cell, as you can see here:

function does what it should do

But when I use the function in a cell like this:

Function doesn't work properly

I get the wrong result. The correct result is what I get if I "hardcode" the tab name in like in this screenshot:

Hardcoded

Why is this, and what can I do to make my function work properly?

Upvotes: 0

Views: 47

Answers (1)

ttaaoossuu
ttaaoossuu

Reputation: 7884

You get the wrong result because your =SUMIFS() compares values to string value "=tabname()", not the result of function tabname(). Try this:

=SUMIFS(Bokningar!E:E;Bokningar!B:B;TabName())-SUM(C:C)

Upvotes: 2

Related Questions