English 中文(简体)
How to circumvent the depth limitation of Excel s IF function?
原标题:

For an Excel formula I need the first cell out of a list of cells which contains a numeric value:

 A  |  B  |  C  | ... |  Z  |
-----------------------------
    | 0.1 | 0.4 | ... | =0.1
    |     | 0.2 | ... | =0.2

I use this schema:

IF(ISNUMERIC(A1);A1;IF(ISNUMERIC(B1);A2;IF(ISNUMERIC(C1);C1;IF(...))))))))

Unfortunately this only works for seven columns, because the maximum length is limited in Excel.

Is there any way to re-phrase this formula so that it doesn t get deeper with every additional column?

问题回答

OK, lets see. Try this

=INDEX(A1:Y1,SUMPRODUCT((A1:Y1="")*1)+1)

The sumproduct counts the number of blanks, then the index looks up the value in the cell where number of blanks + 1

Hope that helps.

In a single cell you can do this with an array formula:

Isnumber provides the test in Excel 2007

Multiply the result by column()

Use an if statement to help the following min function along:

Use the min function to identify the first numeric column.

Remember to use Ctrl-Shift-Enter when you want to make an array formula, not just enter.

=INDEX(A1:Z1,MIN(IF(ISNUMBER(A1:Z1),COLUMN(A1:Z1),5000)))

This also finds the first used column across multiple rows should you need that functionality.

astanders answer works (with the assumption that the cells following the first number are allways filled).

You can also write your own function in a VBA Module.

Public Function getFirstNumber(ByRef sourceRow As Range) As Double
    For Each Cell In sourceRow.Cells
        If WorksheetFunction.IsNumber(Cell) = True Then
            getFirstNumber = Cell.Value
            Exit Function
        End If
    Next Cell
End Function




相关问题
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 ...

热门标签