Option Explicit
Function AUTONUMBER(ByVal oRng As Excel.Range, Optional bCountFromZero As Boolean = True) As Long
Excel.Application.Volatile True
On Error GoTo Err_Hnd_AN
Dim oRngCol As Excel.Range
Dim oWS As Excel.Worksheet
If oRng.Cells.Count <> 1 Then VBA.Err.Raise vbObjectError + 777
Set oWS = oRng.Parent
'Used range gets rid of blanks in the upper portion of column, oWS.Rows("1:" & oRng.Row) limits
'the range to the cell in question up.
Set oRngCol = Excel.Intersect(oWS.Columns(oRng.Column), oWS.UsedRange, oWS.Rows("1:" & oRng.Row))
AUTONUMBER = oRng.Row - GetInvisibleRows(oRngCol)
If bCountFromZero Then AUTONUMBER = AUTONUMBER - 1
Exit Function
Err_Hnd_AN:
End Function
Private Function GetInvisibleRows(oRng As Excel.Range) As Long
'SpecialCells(xlCellTypeVisible).Count does not work when
'called from macro.
Dim oWS As Excel.Worksheet
Dim lLC As Long 'Loop Counter
Dim lUB As Long 'Loop Upper bound
Dim lSum As Long
Set oWS = oRng.Parent
lUB = oRng.Rows.Count
For lLC = 1 To lUB
If oWS.Rows(lLC).RowHeight = 0 Then lSum = lSum + 1
Next lLC
GetInvisibleRows = lSum
End Function