What does the Excel range.Rows property really do?

前端 未结 9 1994
故里飘歌
故里飘歌 2021-01-30 16:21

OK, I am finishing up an add-on project for a legacy Excel-VBA application, and I have once again run up against the conundrum of the mysterious range.Rows (?) and

9条回答
  •  天命终不由人
    2021-01-30 16:34

    Since the .Rows result is marked as consisting of rows, you can "For Each" it to deal with each row individually, like this:

    Function Attendance(rng As Range) As Long
    Attendance = 0
    For Each rRow In rng.Rows
        If WorksheetFunction.Sum(rRow) > 0 Then
            Attendance = Attendance + 1
        End If
    Next
    End Function
    

    I use this to check attendance in any of a few categories (different columns) for a list of people (different rows).

    (And of course you could use .Columns to do a "For Each" over the columns in the range.)

提交回复
热议问题