How can I count the rows with data in an Excel sheet?

后端 未结 6 2034
情书的邮戳
情书的邮戳 2021-01-04 08:24

I am trying to count the number of rows in a spreadsheet which contain at least one non-blank value over a few columns: i.e.

row 1 has a text value in column         


        
相关标签:
6条回答
  • 2021-01-04 08:40

    If you don't mind VBA, here is a function that will do it for you. Your call would be something like:

    =CountRows(1:10) 
    
    Function CountRows(ByVal range As range) As Long
    
    Application.ScreenUpdating = False
    Dim row As range
    Dim count As Long
    
    For Each row In range.Rows
        If (Application.WorksheetFunction.CountBlank(row)) - 256 <> 0 Then
            count = count + 1
        End If
    Next
    
    CountRows = count
    Application.ScreenUpdating = True
    
    End Function
    

    How it works: I am exploiting the fact that there is a 256 row limit. The worksheet formula CountBlank will tell you how many cells in a row are blank. If the row has no cells with values, then it will be 256. So I just minus 256 and if it's not 0 then I know there is a cell somewhere that has some value.

    0 讨论(0)
  • 2021-01-04 08:55

    If you want a simple one liner that will do it all for you (assuming by no value you mean a blank cell):

    =(ROWS(A:A) + ROWS(B:B) + ROWS(C:C)) - COUNTIF(A:C, "")
    

    If by no value you mean the cell contains a 0

    =(ROWS(A:A) + ROWS(B:B) + ROWS(C:C)) - COUNTIF(A:C, 0)
    

    The formula works by first summing up all the rows that are in columns A, B, and C (if you need to count more rows, just increase the columns in the range. E.g. ROWS(A:A) + ROWS(B:B) + ROWS(C:C) + ROWS(D:D) + ... + ROWS(Z:Z)).

    Then the formula counts the number of values in the same range that are blank (or 0 in the second example).

    Last, the formula subtracts the total number of cells with no value from the total number of rows. This leaves you with the number of cells in each row that contain a value

    0 讨论(0)
  • 2021-01-04 08:55

    You should use the sumif function in Excel:

    =SUMIF(A5:C10;"Text_to_find";C5:C10)

    This function takes a range like this square A5:C10 then you have some text to find this text can be in A or B then it will add the number from the C-row.

    0 讨论(0)
  • 2021-01-04 08:59

    With formulas, what you can do is:

    • in a new column (say col D - cell D2), add =COUNTA(A2:C2)
    • drag this formula till the end of your data (say cell D4 in our example)
    • add a last formula to sum it up (e.g in cell D5): =SUM(D2:D4)
    0 讨论(0)
  • 2021-01-04 09:00

    Try this scenario:

    Array = A1:C7. A1-A3 have values, B2-B6 have value and C1, C3 and C6 have values.

    To get a count of the number of rows add a column D (you can hide it after formulas are set up) and in D1 put formula =If(Sum(A1:C1)>0,1,0). Copy the formula from D1 through D7 (for others searching who are not excel literate, the numbers in the sum formula will change to the row you are on and this is fine).

    Now in C8 make a sum formula that adds up the D column and the answer should be 6. For visually pleasing purposes hide column D.

    0 讨论(0)
  • 2021-01-04 09:01

    This is what I finally came up with, which works great!

    {=SUM(IF((ISTEXT('Worksheet Name!A:A))+(ISTEXT('CCSA Associates'!E:E)),1,0))-1}

    Don't forget since it is an array to type the formula above without the "{}", and to CTRL + SHIFT + ENTER instead of just ENTER for the "{}" to appear and for it to be entered properly.

    0 讨论(0)
提交回复
热议问题