0

I have created a UDF that returns the last populated row in a specific column. Right now, it returns the row number of the last populated row. My question is, how would I go about using this value in a worksheet function?

For example, =COUNTBLANK("B2:B&LastRow(2)), where LastRow(2) returns an integer.

Community
  • 1
  • 1

2 Answers2

0

First the UDF

Public Function LastRow(Rin As Range) As Long
    cl = Rin.Column
    LastRow = Cells(Rows.Count, cl).End(xlUp).Row
End Function

and then to use it in the worksheet:

=COUNTBLANK(INDIRECT("B2:B"& LastRow(B:B)))
Gary's Student
  • 95,722
  • 10
  • 59
  • 99
0

Why use VBA when you can achieve what you want with formulas?

To get the last row in a column, use this formula.

=MATCH(9.9E+307,A:A,1)

The above will give you the last row of a column A

To use it with your formula try this.

=COUNTBLANK(INDIRECT("B2:B"& MATCH(9.9E+307,B:B,1)))
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250