Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default End(xlDown) function

I have the following function to return the last row number in a column of
numbers:

Function LastRowNum()
Application.Volatile
LastRowNum = ActiveCell.End(xlDown).Row
End Function

Problem, I want it to return the last row number starting from the cell the
function is in, not starting from the active cell. ActiveCell obviously has
to come out, but what do I replace it with?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default End(xlDown) function

You can use Application.Caller:

Option Explicit
Function LastRowNum()

Dim myCell As Range

Application.Volatile

Set myCell = Application.Caller
LastRowNum = myCell.End(xlDown).Row

End Function

I added the application.volatile so that the UDF would re-evaluate whenever
excel recalculated. But I wouldn't trust the results of the UDF until I forced
a recalc (by hitting F9).

Another way around it is to pass the entire column for that formula:

Option Explicit
Function LastRowNum(myCol As Range)
Dim myCell As Range
Set myCell = Application.Caller
LastRowNum = myCell.End(xlDown).Row
End Function

And use it like:
=LastRowNum(I:I)
(when the formula is in a cell in column I)

By passing the column, excel realizes that when something changes in that
column, it has to reevaluate that UDF.



John wrote:

I have the following function to return the last row number in a column of
numbers:

Function LastRowNum()
Application.Volatile
LastRowNum = ActiveCell.End(xlDown).Row
End Function

Problem, I want it to return the last row number starting from the cell the
function is in, not starting from the active cell. ActiveCell obviously has
to come out, but what do I replace it with?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default End(xlDown) function

Function LastRowNum()
Application.Volatile
Set r = Range(Application.Caller.Address)
LastRowNum = r.End(xlDown).Row
End Function

--
Gary''s Student - gsnu200852


"John" wrote:

I have the following function to return the last row number in a column of
numbers:

Function LastRowNum()
Application.Volatile
LastRowNum = ActiveCell.End(xlDown).Row
End Function

Problem, I want it to return the last row number starting from the cell the
function is in, not starting from the active cell. ActiveCell obviously has
to come out, but what do I replace it with?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default End(xlDown) function

This could cause trouble if the function is used in different sheets. The
unqualifed Range() will refer to the activesheet--not the sheet that contains
the formula.



Gary''s Student wrote:

Function LastRowNum()
Application.Volatile
Set r = Range(Application.Caller.Address)
LastRowNum = r.End(xlDown).Row
End Function

--
Gary''s Student - gsnu200852

"John" wrote:

I have the following function to return the last row number in a column of
numbers:

Function LastRowNum()
Application.Volatile
LastRowNum = ActiveCell.End(xlDown).Row
End Function

Problem, I want it to return the last row number starting from the cell the
function is in, not starting from the active cell. ActiveCell obviously has
to come out, but what do I replace it with?




--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A1:B(xlDown)? Simon[_2_] Excel Programming 5 July 29th 08 10:23 AM
End(XlDown).Row - Problem if only 1 row Ed Peters Excel Programming 2 September 12th 07 09:11 PM
End(xlDown) not working? RAHokie Excel Discussion (Misc queries) 2 January 19th 07 12:40 AM
repeated end(xldown) R.VENKATARAMAN Excel Programming 6 December 28th 05 06:43 PM
XlDown: Go to next blank row tomwashere2 Excel Programming 2 August 16th 05 11:15 PM


All times are GMT +1. The time now is 11:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"