Public Function.

How_Do_I

Well-known Member
Joined
Oct 23, 2009
Messages
1,831
Office Version
  1. 2010
Platform
  1. Windows
Hi…
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
The Jeanie is working using the following Public Function:
<o:p></o:p>
Rich (BB code):
Public Function V(Optional vrnt As Variant) As Variant<o:p></o:p>
Rich (BB code):
'<o:p></o:p>
' Stephen Dunn<o:p></o:p>
' 2002-09-12<o:p></o:p>
'<o:p></o:p>
Static vrntV As Variant<o:p></o:p>
If Not IsMissing(vrnt) Then vrntV = vrnt<o:p></o:p>
V = vrntV<o:p></o:p>
End Function
<o:p></o:p>
It is giving the red highlighted results.
<o:p></o:p>
However, when I remove the data in Row A3:E3 everything disappears from the red highlighted area… It should return the “1”. Obviously this is a much reduced Jeanie to show my issue but strangely I get a #NUM error in my full workbook where as in this Jeanie example I get nothing.
<o:p></o:p>
Can anyone see what is going wrong please?

Sheet1

<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Arial,Arial; FONT-SIZE: 10pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 32px"><COL style="WIDTH: 32px"><COL style="WIDTH: 133px"><COL style="WIDTH: 133px"><COL style="WIDTH: 71px"><COL style="WIDTH: 71px"><COL style="WIDTH: 84px"><COL style="WIDTH: 64px"><COL style="WIDTH: 87px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD></TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD></TR><TR style="HEIGHT: 59px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">1</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Ref</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Week</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Home</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Away</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Date</TD><TD style="FONT-WEIGHT: bold"></TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Matches</TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2</TD><TD style="TEXT-ALIGN: center">1</TD><TD></TD><TD>Hull City</TD><TD>Blackpool</TD><TD style="TEXT-ALIGN: right">11/11/2011</TD><TD></TD><TD style="TEXT-ALIGN: right">2</TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">3</TD><TD style="TEXT-ALIGN: center">2</TD><TD></TD><TD>Coventry City</TD><TD>Leicester City</TD><TD style="TEXT-ALIGN: right">11/11/2011</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">4</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">5</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD style="BACKGROUND-COLOR: #ffff00"></TD><TD style="BACKGROUND-COLOR: #ffff00">Blackpool</TD><TD style="BACKGROUND-COLOR: #ffff00">Leicester City</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">6</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD style="BACKGROUND-COLOR: #ffff00">Hull City</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ff0000">1</TD><TD style="BACKGROUND-COLOR: #ff0000"></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">7</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD style="BACKGROUND-COLOR: #ffff00">Coventry City</TD><TD style="BACKGROUND-COLOR: #ff0000"></TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ff0000">2</TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">8</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR></TBODY></TABLE>
<TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; FONT-SIZE: 10pt; BORDER-LEFT-STYLE: groove; BORDER-LEFT-COLOR: #00ff00"><TBODY><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TBODY><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>G2</TD><TD>=COUNT(Date)</TD></TR><TR><TD>H6</TD><TD>{=IF(ISNUMBER(V(MATCH(1,IF(Home=$G6,IF(Away=H$5,1,"")),0))),V(),"")}</TD></TR><TR><TD>I6</TD><TD>{=IF(ISNUMBER(V(MATCH(1,IF(Home=$G6,IF(Away=I$5,1,"")),0))),V(),"")}</TD></TR><TR><TD>H7</TD><TD>{=IF(ISNUMBER(V(MATCH(1,IF(Home=$G7,IF(Away=H$5,1,"")),0))),V(),"")}</TD></TR><TR><TD>I7</TD><TD>{=IF(ISNUMBER(V(MATCH(1,IF(Home=$G7,IF(Away=I$5,1,"")),0))),V(),"")}</TD></TR></TBODY></TABLE></TD></TR><TR><TD>Formula Array:
Produce enclosing { } by entering
formula with CTRL+SHIFT+ENTER!

</TD></TR><TR><TD><TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; FONT-SIZE: 10pt; BORDER-LEFT-STYLE: groove; BORDER-LEFT-COLOR: #00ff00"><TBODY><TR><TD>Names in Formulas </TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TBODY><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Name</TD><TD>Applies to</TD></TR><TR><TD>G2</TD><TD>Date</TD><TD>=Sheet1!$E$2:$E$18</TD></TR><TR><TD>H6</TD><TD>Away</TD><TD>=INDEX(ResultsArea,,4)</TD></TR><TR><TD>H6</TD><TD>Home</TD><TD>=INDEX(ResultsArea,,3)</TD></TR><TR><TD>H6</TD><TD>ResultsArea</TD><TD>=Sheet1!$A$2:INDEX(Sheet1!$D:$D,Sheet1!$G$2+1)</TD></TR><TR><TD>I6</TD><TD>Away</TD><TD>=INDEX(ResultsArea,,4)</TD></TR><TR><TD>I6</TD><TD>Home</TD><TD>=INDEX(ResultsArea,,3)</TD></TR><TR><TD>I6</TD><TD>ResultsArea</TD><TD>=Sheet1!$A$2:INDEX(Sheet1!$D:$D,Sheet1!$G$2+1)</TD></TR><TR><TD>H7</TD><TD>Away</TD><TD>=INDEX(ResultsArea,,4)</TD></TR><TR><TD>H7</TD><TD>Home</TD><TD>=INDEX(ResultsArea,,3)</TD></TR><TR><TD>H7</TD><TD>ResultsArea</TD><TD>=Sheet1!$A$2:INDEX(Sheet1!$D:$D,Sheet1!$G$2+1)</TD></TR><TR><TD>I7</TD><TD>Away</TD><TD>=INDEX(ResultsArea,,4)</TD></TR><TR><TD>I7</TD><TD>Home</TD><TD>=INDEX(ResultsArea,,3)</TD></TR><TR><TD>I7</TD><TD>ResultsArea</TD><TD>=Sheet1!$A$2:INDEX(Sheet1!$D:$D,Sheet1!$G$2+1)</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Jeanie with second row of data removed...

Excel Workbook
ABCDEFGHIJ
1RefWeekHomeAwayDateMatches
21Hull CityBlackpool11/11/20111
3
4
5BlackpoolLeicester City
6Hull City  
7Coventry City  
8
Sheet1
#VALUE!
</td></tr></table></td></tr></table>
 
Upvote 0
It's not V(). Rather the MATCH bit. Such an outcome obtains only when there is just one record in the data area and the IF bit returns just a 1. MATCH(1,1,0) will invariably fail. Hence the empty result area.

Modify the formula in H6 to:

=IF(ISNUMBER(V(MATCH(1,{0}+IF(Home=$G6,IF(Away=H$5,1,"")),0))),V(),"")

which still needs to be confirmed with control+shift+enter.

Just with a single record to go, the MATCH bit will become:

MATCH(1,{1},0)

That is, MATCH gets, as needed, an array for comparison/matching, not a scalar.
 
Upvote 0
Hi Aladin…
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
Your solution is great, it works so thanks for that… I'm a little confused though... How come this works, it’s the original formula with different formulas for the named ranges. Any ideas about that please?

Excel Workbook
ABCDEFGHIJ
1RefWeekHomeAwayDateMatches
21Hull CityBlackpool11/11/20111
3
4
5BlackpoolLeicester City
6Hull City1
7Coventry City
8
Sheet1
#VALUE!
</td></tr></table></td></tr></table>

 
Upvote 0
Hi Aladin…
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Your solution is great, it works so thanks for that… I'm a little confused though... How come this works, it’s the original formula with different formulas for the named ranges. Any ideas about that please?

Sheet1

<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Arial,Arial; FONT-SIZE: 10pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 32px"><COL style="WIDTH: 32px"><COL style="WIDTH: 133px"><COL style="WIDTH: 133px"><COL style="WIDTH: 71px"><COL style="WIDTH: 71px"><COL style="WIDTH: 84px"><COL style="WIDTH: 64px"><COL style="WIDTH: 87px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD></TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD><TD>J</TD></TR><TR style="HEIGHT: 59px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">1</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Ref</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Week</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Home</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Away</TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Date</TD><TD style="FONT-WEIGHT: bold"></TD><TD style="TEXT-ALIGN: left; BACKGROUND-COLOR: #ffff00; FONT-WEIGHT: bold">Matches</TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">2</TD><TD style="TEXT-ALIGN: center">1</TD><TD></TD><TD>Hull City</TD><TD>Blackpool</TD><TD style="TEXT-ALIGN: right">11/11/2011</TD><TD></TD><TD style="TEXT-ALIGN: right">1</TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">3</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">4</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">5</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD style="BACKGROUND-COLOR: #ffff00"></TD><TD style="BACKGROUND-COLOR: #ffff00">Blackpool</TD><TD style="BACKGROUND-COLOR: #ffff00">Leicester City</TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">6</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD style="BACKGROUND-COLOR: #ffff00">Hull City</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #ff0000">1</TD><TD style="BACKGROUND-COLOR: #ff0000"></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">7</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD style="BACKGROUND-COLOR: #ffff00">Coventry City</TD><TD style="BACKGROUND-COLOR: #ff0000"></TD><TD style="BACKGROUND-COLOR: #ff0000"></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">8</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR></TBODY></TABLE>
<TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; BORDER-LEFT-STYLE: groove; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; FONT-SIZE: 10pt; BORDER-LEFT-COLOR: #00ff00"><TBODY><TR><TD>Spreadsheet Formulas</TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TBODY><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Formula</TD></TR><TR><TD>G2</TD><TD>=COUNT(Date)</TD></TR><TR><TD>H6</TD><TD>{=IF(ISNUMBER(V(MATCH(1,IF(Home=$G6,IF(Away=H$5,1,"")),0))),V(),"")}</TD></TR></TBODY></TABLE></TD></TR><TR><TD>Formula Array:
Produce enclosing { } by entering
formula with CTRL+SHIFT+ENTER!
</TD></TR><TR><TD><TABLE style="BORDER-BOTTOM-STYLE: groove; BORDER-BOTTOM-COLOR: #00ff00; BACKGROUND-COLOR: #fffcf9; BORDER-TOP-COLOR: #00ff00; BORDER-LEFT-STYLE: groove; FONT-FAMILY: Arial; BORDER-TOP-STYLE: groove; COLOR: #000000; BORDER-RIGHT-COLOR: #00ff00; BORDER-RIGHT-STYLE: groove; FONT-SIZE: 10pt; BORDER-LEFT-COLOR: #00ff00"><TBODY><TR><TD>Names in Formulas </TD></TR><TR><TD><TABLE style="FONT-FAMILY: Arial; FONT-SIZE: 9pt" border=1 cellSpacing=0 cellPadding=2><TBODY><TR style="BACKGROUND-COLOR: #cacaca; FONT-SIZE: 10pt"><TD>Cell</TD><TD>Name</TD><TD>Applies to</TD></TR><TR><TD>G2</TD><TD>Date</TD><TD>=Sheet1!$E$2:$E$3</TD></TR><TR><TD>H6</TD><TD>Away</TD><TD>=Sheet1!$D$2:$D$3</TD></TR><TR><TD>H6</TD><TD>Home</TD><TD>=Sheet1!$C$2:$C$3</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4

You have 2 records here, not 1. That means the MATCH bit gets an array to look at, not a single value.
 
Upvote 0
I think I get it now Aladin... My last post is one record but the named ranges are looking at a range that covers 2 records.

This Jeanie has failed, original formula looking at a range that covers a single record...

Thanks for your help :)

Excel Workbook
ABCDEFGHIJ
1RefWeekHomeAwayDateMatches
21Hull CityBlackpool11/11/20111
3
4
5BlackpoolLeicester City
6Hull City 
7Coventry City
Sheet1
#VALUE!
</td></tr></table></td></tr></table>
 
Upvote 0
I think I get it now Aladin... My last post is one record but the named ranges are looking at a range that covers 2 records.

A 2 record range delivers a 2 item-array to MATCH.
In the original situation, where you deleted 1 record from the 2 record area, MATCH gets a single value (a scalar value), not an array. The extension with {0}+ forces the single value to go into an array structure with a single item/value in it.

That is: 1 vs {1}

The first is a scalar value, the last an array. MATCH needs an array.

This Jeanie has failed, original formula looking at a range that covers a single record...

You seem to be in love with this Jeanie thing:LOL:...
 
Upvote 0
Just a little observation, you don't need a custom function to do that.

=SUMPRODUCT((Home=$G6)*(Away=H$5)*Ref)

Format the red cells using [=0]"";#
 
Upvote 0
Just a little observation, you don't need a custom function to do that.

=SUMPRODUCT((Home=$G6)*(Away=H$5)*Ref)

Format the red cells using [=0]"";#

I will look at that Jason... The custom function was introduced to stop errors returns and/or double calculations when a game has not been played.

Your solution returns a "0" if the game hasn't been played so your solution has already become a double calculation:

=IF(SUMPRODUCT((Home=$BM12)*(Away=BN$1)*Ref)=0,"",SUMPRODUCT((Home=$BM12)*(Away=BN$1)*Ref))
 
Upvote 0

Forum statistics

Threads
1,216,122
Messages
6,128,958
Members
449,480
Latest member
yesitisasport

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