Code:
=SUM(IF(ISNUMBER(SEARCH(RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2))),'Sports Daily'!B544:B620)),'Sports Daily'!C544:C620,0))
Working from the inside out...
The Cell() function returns information about the workbook. In this case, I am retrieveing the file/pathname of the workbook (BTW: the file needs to be saved, other wsie, none of this will work). For example:
will return D:\Documents and Settings\sasurpa\Desktop\[test1.xls]ATP...
Code:
LEN(CELL("filename",ATP!A2))
returns the length of the file/pathname = 56...
Code:
FIND("]",CELL("filename",ATP!A2))
determines the location of the ] in the string = 53...
Code:
RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2)))
will return the rightmost N characters of the string... in this case N = 56-53 = 3, so the result is ATP: you sheetname. The nature of this set of formulas is that when you change the name of Sheet ATP, the result updates so it always returns the sheet name.
Code:
SEARCH(RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2))),'Sports Daily'!B544:B620)
will determine the location of ATP in each member of 'Sports Daily'!B544:B620. The result (when you confirm with Ctrl+Shift+Enter) is an array of 76 results, on for each cell. When ATP is found in a cell, the result is an integer indicating the start position of the search string. When ATP is NOT found, the result is #VALUE.
Code:
ISNUMBER(SEARCH(RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2))),'Sports Daily'!B544:B620))
will return an array of 76 results, either True or False based on whether the reult of the previous is a number or not.
Code:
IF(ISNUMBER(SEARCH(RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2))),'Sports Daily'!B544:B620)),'Sports Daily'!C544:C620,0)
will return an array of 76 results, either 0 if ATP was not found in the cell, or the corresponding numerical value located in 'Sports Daily'!C544:C620 when ATP was found in the cell.
Code:
SUM(IF(ISNUMBER(SEARCH(RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2))),'Sports Daily'!B544:B620)),'Sports Daily'!C544:C620,0))
simply sums up the numerical results of the 76 member array.
2 things to be aware of: 1) your file must be saved for this to work. 2) You must confirm with Ctrl+Shift+Enter, which (when accepted by Excel) will cause curly brackets {} to appear around the formula, like this
Code:
{=SUM(IF(ISNUMBER(SEARCH(RIGHT(CELL("filename",ATP!A1),LEN(CELL("filename",ATP!A2))-FIND("]",CELL("filename",ATP!A2))),'Sports Daily'!B544:B620)),'Sports Daily'!C544:C620,0))}