English 中文(简体)
Excel: parse text as formula
原标题:

I would like to have part of an excel formula be dynamic, other than a cell reference.

For instance, suppose that in column A (cells A1:A99) I have a bunch of numbers, and I want to know how many of those numbers are greater than 50.

If I wanted this calculation to be static, I could simply use one of the following:

=COUNTIF($A$1:$A$99,">50")
=SUM(IF($A$1:$A$99>50,1,0))
=SUM(($A$1:$A$99>50)*1)

I mention all three because my actual formula is hairy and a bit of a mix of the second and the third. (After all, perhaps something will work with COUNTIF but not with the others.)

Now, I want to be able to type my condition in another cell (say C1). So if I type ">50" in C1, my calculation will be as above, but if I type "<100" I will count how many entries of column A are less than 100.

Is this possible? (I am using Excel 2003 on Windows XP.)

问题回答

There may be something that I m missing. If you give

=COUNTIF($A$1:$A$99,C1)

in any cell, and then in cell C1 you type >50 or <100 don t you get what you want?

Use INDIRECT

=INDIRECT(COUNTIF($A$1:$A$99,">50"))

is same as

=COUNTIF($A$1:$A$99,">50")

But, as you identified, the former, you can generate within the excel cells! I do it all the time, for such things.

I usually solve this by adding another column carrying the result of a complex logical expression, like

=AND(OR(C3<D3;E3>=100);A3=VLOOKUP(B3;Sheet2!$A$2:$B$212;2;FALSE))

this formula is in all rows of -say- column F - note: no IF needed here!

then I calculate a complex conditional sum across column E using =SUMIF() like

=SUMIF(F2:F57;TRUE;E2:E57)

I know that some users say "I do not want to change my design. That s ok; my argument is that I have better control over the condition, I can work on the condition seperately from summing up or other functions that rely on that condition, and I can filter records for TRUE or FALSE to look at the subsets and have a rapid overview if the formula makes sense

hope that helps Good luck MikeD





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签