CountRowCells

Counts how many cells with data in a row, starting from certain column until end of row
Similar to CountColumnCells() but for columns in a certain row.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function CountRowCells(RowNumber, Optional WB = "This", Optional Shee = "Active", Optional StartFromColumnNumber = 1, Optional Or_StartFromColumnName = "A")
    ' Counts how many cells with data in a row, starting from certain column until end of row
    '    Similar to CountColumnCells()
    '
    Rett = 0
    If WB = "This" Then WB = ThisWorkbook.Name
    If WB = "Active" Then WB = ActiveWorkbook.Name
    If Shee = "Active" Then Shee = ActiveSheet.Name
    RowNumber = IIf(RowNumber < 1, 1, RowNumber)
    StartFromColIndex = IIf(StartFromColumnNumber < 1, 1, StartFromColumnNumber) ' Default to use StartFromColumnNumber
    If StartFromColumnNumber = 1 And Or_StartFromColumnName < > "A" Then ' Unless we defined Or_StartFromColumnName
        StartFromColIndex = Range(Or_StartFromColumnName & 1).Column
    End If
    EndColumnNumber = Range("A1").EntireRow.Columns.Count
    CellAdd1 = Cells(RowNumber, StartFromColIndex).Address
    CellAdd2 = Cells(RowNumber, EndColumnNumber).Address
    Rett = WorksheetFunction.CountA(Workbooks(WB).Worksheets(Shee).Range(CellAdd1, CellAdd2))
    CountRowCells = Rett
End Function

RowNumber, Optional WB = "This", Optional Shee = "Active", Optional StartFromColumnNumber = 1, Optional Or_StartFromColumnName = "A"

Views 172

Downloads 34

CodeID
DB ID