return the current row number for use in a formula

C

CuriousMark

How do I return the row number of the current (not necessarily active) cell
for use in a custom formula? =Row() in a cell returns that cell's row number,
but I can't figure out how to use that in a custom formula. For example, code
such as this doesn't work because Excel gives me a compile error on "=Row()".

Public Function myFunction()
Dim Variable As Integer, Result As Integer
Variable = Row()
Result = Variable + 10
myFunction = Result
End Function

Thanks very much.
 
D

Dave Peterson

Option Explicit
Public Function myFunction() As Long
Dim Variable As Long
Dim Result As Long
Variable = application.caller.Row
Result = Variable + 10
myFunction = Result
End Function

or just:

Option Explicit
Public Function myFunction() As Long
myFunction = application.caller.row + 10
End Function
 
C

CuriousMark

Thanks very much Dave. I tried to find the answer in the Discussion groups,
in my books and on-line, and it was frustratingly difficult. I knew it would
be simple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top