Archive of Mr Excel Message Board
I have a CSE formula that contains a few if statements, that are looking at a query on another sheet called "Data". The formula looks something like this:
=SUM(IF(Data!$C$1:$C$64000=A15,IF(Data!$D$1:$D$64000=0,Data!$F$1:$F$64000,0)))
The above works fine however when I refresh the query, all the formulas on the first sheet containing the above query show the error #NUM! I have not included field names in the query results, but it still seems to show the same error. Does anyone have an idea on how to prevent this form happening.
Thanks,
Anton.

| Check out our Excel Resources | ||||
![]() |
![]() |
|||

Thanks for the response, but all the numerical columns in the data page are formatted as numeric. I used the =ISNUMBER() formaula to check all the numbers, and they all came back as true. The funny thing that happens, is when I refesh the query on the "Data" page, all the formulas loose their cell numbering reference. For example, the cell references $C$1:$C$64000 becomes $C:$C!. If I change back the cell references, the formula works ok. Does anybody have any other ideas?

Two proposals.
On Data:
(1)
Activate Insert|Name|Define.
Enter NumRecs in the Names in Workbook box.
Enter the following formula in the Refers To box.
=COUNTA(Data!$C:$C)
Click Add.
Don't close the Define Name window.
Enter CRANGE (or any sensible descriptive name) in the Names in Workbook box.
Enter the following formula in the Refers To box.
=OFFSET(Data!$C$1,0,0,NumRecs,1)
Click Add.
Enter DRANGE (or any sensible descriptive name) in the Names in Workbook box.
Enter the following formula in the Refers To box.
=OFFSET(Data!$D$1,0,0,NumRecs,1)
Click Add.
Enter FRANGE (or any sensible descriptive name) in the Names in Workbook box.
Enter the following formula in the Refers To box.
=OFFSET(Data!$F$1,0,0,NumRecs,1)
Click OK.
Change your CSE formula to:
=SUM(IF(CRANGE=A15,IF(DRANGE=0,FRANGE,0)))
By the way, an alternative CSE formula would be:
=SUM((CRANGE=A15)*(DRANGE=0)*(FRANGE))
or a non-CSE formula:
=SUMPRODUCT((CRANGE=A15)*(DRANGE=0)*(FRANGE))
(2)
Activate the option Tools|Macro|Visual Basic Editor.
Activate Insert|Module.
Paste the following user-defined function in the window with the "(code)" bit in the title:
Function Used(r As Range) As Range
'
' Harlan Grove
'
Dim q As Range
Set q = r.Parent.UsedRange.Cells(r.Parent.UsedRange.Cells.Count)
Set Used = Intersect(r, r.Parent.Range(Cells(1, 1), q))
End Function
Activate File|Close and Return to Microsoft Excel.
Activate A15. Type CRIT (or any other sensible name) in the Name Box on the Formula Bar.
Modify one of the formulas that you prefer to use for the task at hand as follows (I pick the SUMPRODUCT version, others also will do):
=SUMPRODUCT((USED(C:C)=CRIT)*(USED(D:D)=0)*(USED(F:F))
Now, this is important, the modified formula must be entered in some cell in DATA.
Obviously, you need to use the result in another worksheet. Simply refer to the cell of this formula in the target worksheet.
Note. Use one of the options, not both at the same time.
Aladin
================

