Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default LastRow function - #VALUE


Need help... I got this macro from ExcelTip.com (thanks to Ron de Bruin)
basically to find the last filled row.

I would like to use this as a worksheet function in cell (A2). As
such, I entered =LastRow(), but the result is #VALUE. I did not pass
any parameter into the function as I assume it will take the current
Activesheet.

Can someone help to show some lights with regards to this problem?
Thanks in advance.


Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


--
slc
------------------------------------------------------------------------
slc's Profile: http://www.excelforum.com/member.php...fo&userid=1439
View this thread: http://www.excelforum.com/showthread...hreadid=400016

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default LastRow function - #VALUE

Find doesn't work in a UDF pre Excel 2002.

If you have Excel 2000 or earlier, try this

Function LastRow(rng As Range)
Dim temp, temp1
Dim col As Range
With Application.Caller.Parent
For Each col In rng.Columns
temp = Cells(Rows.Count, rng.Column).End(xlUp).Row
If temp temp1 Then temp1 = temp
Next col
End With
LastRow = temp1
End Function

and use like so

=LastRow(A:E)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"slc" wrote in message
...

Need help... I got this macro from ExcelTip.com (thanks to Ron de Bruin)
basically to find the last filled row.

I would like to use this as a worksheet function in cell (A2). As
such, I entered =LastRow(), but the result is #VALUE. I did not pass
any parameter into the function as I assume it will take the current
Activesheet.

Can someone help to show some lights with regards to this problem?
Thanks in advance.


Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


--
slc
------------------------------------------------------------------------
slc's Profile:

http://www.excelforum.com/member.php...fo&userid=1439
View this thread: http://www.excelforum.com/showthread...hreadid=400016



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default LastRow function - #VALUE

Hi Bob

Working for me in Excel 2000


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Bob Phillips" wrote in message ...
Find doesn't work in a UDF pre Excel 2002.

If you have Excel 2000 or earlier, try this

Function LastRow(rng As Range)
Dim temp, temp1
Dim col As Range
With Application.Caller.Parent
For Each col In rng.Columns
temp = Cells(Rows.Count, rng.Column).End(xlUp).Row
If temp temp1 Then temp1 = temp
Next col
End With
LastRow = temp1
End Function

and use like so

=LastRow(A:E)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"slc" wrote in message
...

Need help... I got this macro from ExcelTip.com (thanks to Ron de Bruin)
basically to find the last filled row.

I would like to use this as a worksheet function in cell (A2). As
such, I entered =LastRow(), but the result is #VALUE. I did not pass
any parameter into the function as I assume it will take the current
Activesheet.

Can someone help to show some lights with regards to this problem?
Thanks in advance.


Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


--
slc
------------------------------------------------------------------------
slc's Profile:

http://www.excelforum.com/member.php...fo&userid=1439
View this thread: http://www.excelforum.com/showthread...hreadid=400016





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default LastRow function - #VALUE

Hi

This is not a worksheet function
You must use it in VBA like this LastRow(Activsheet)

For a worksheetfunction see this from Harlan Grove

Use it like this
=lc()

Function lr(Optional r As Range) As Variant
Dim ur As Range, c As Range, i As Long, n As Long

'there arguments for & against volatility - optional to uncomment
Application.Volatile

If r Is Nothing Then Set r = Application.Caller
If Not TypeOf r Is Range Then Set r = ActiveCell

Set ur = r.Parent.UsedRange
n = ur.Rows.Count

For i = n To 1 Step -1
Set c = ur.Cells(i, 1)
If Not IsEmpty(c.Value) Then Exit For
If Not IsEmpty(c.End(xlToRight).Value) Then Exit For
Next i

lr = ur.Row + i - 1
End Function


Function lc(Optional r As Range) As Variant
Dim ur As Range, c As Range, i As Long, n As Long

'there arguments for & against volatility - optional to uncomment
Application.Volatile

If r Is Nothing Then Set r = Application.Caller
If Not TypeOf r Is Range Then Set r = ActiveCell

Set ur = r.Parent.UsedRange
n = ur.Columns.Count

For i = n To 1 Step -1
Set c = ur.Cells(1, i)
If Not IsEmpty(c.Value) Then Exit For
If Not IsEmpty(c.End(xlDown).Value) Then Exit For
Next i

lc = ur.Column + i - 1
End Function



--
Regards Ron de Bruin
http://www.rondebruin.nl


"slc" wrote in message ...

Need help... I got this macro from ExcelTip.com (thanks to Ron de Bruin)
basically to find the last filled row.

I would like to use this as a worksheet function in cell (A2). As
such, I entered =LastRow(), but the result is #VALUE. I did not pass
any parameter into the function as I assume it will take the current
Activesheet.

Can someone help to show some lights with regards to this problem?
Thanks in advance.


Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


--
slc
------------------------------------------------------------------------
slc's Profile: http://www.excelforum.com/member.php...fo&userid=1439
View this thread: http://www.excelforum.com/showthread...hreadid=400016



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default LastRow function - #VALUE

Oops

See reply to the OP


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
Hi Bob

Working for me in Excel 2000


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Bob Phillips" wrote in message ...
Find doesn't work in a UDF pre Excel 2002.

If you have Excel 2000 or earlier, try this

Function LastRow(rng As Range)
Dim temp, temp1
Dim col As Range
With Application.Caller.Parent
For Each col In rng.Columns
temp = Cells(Rows.Count, rng.Column).End(xlUp).Row
If temp temp1 Then temp1 = temp
Next col
End With
LastRow = temp1
End Function

and use like so

=LastRow(A:E)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"slc" wrote in message
...

Need help... I got this macro from ExcelTip.com (thanks to Ron de Bruin)
basically to find the last filled row.

I would like to use this as a worksheet function in cell (A2). As
such, I entered =LastRow(), but the result is #VALUE. I did not pass
any parameter into the function as I assume it will take the current
Activesheet.

Can someone help to show some lights with regards to this problem?
Thanks in advance.


Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


--
slc
------------------------------------------------------------------------
slc's Profile:

http://www.excelforum.com/member.php...fo&userid=1439
View this thread: http://www.excelforum.com/showthread...hreadid=400016







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
Lastrow Bishop Excel Worksheet Functions 2 May 13th 09 05:22 PM
Lastrow - function not defined seed Excel Discussion (Misc queries) 2 August 7th 08 06:34 PM
'LastRow' Function not working Randy Reese[_2_] Excel Programming 4 July 17th 04 03:44 AM
Go to lastrow using other column's lastrow stakar[_14_] Excel Programming 5 April 16th 04 03:42 PM
Help with LastRow JStone0218 Excel Programming 4 December 4th 03 04:50 PM


All times are GMT +1. The time now is 04:48 PM.

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"