Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
m&m m&m is offline
external usenet poster
 
Posts: 3
Default detect last row of data

Hi guys,

any Macro that can be written to detect the last row of data ?
please help


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default detect last row of data

You are asking one of the most frequently asked questions in this newsgroup.
A Google search will answer a lot of questions before you have to ask.

The following function usually works for me...

'=======================================
' GetBottomRow() Function
' Jim Cone did it
' Returns the number of the last worksheet row with data.
' If the sheet is blank it returns 0.
'=======================================
Function GetBottomRow(ByRef TheSheet as Worksheet) As Long
On Error GoTo NoRow
' Line below is optional. Also a check for hidden rows could be done instead.
If TheSheet.FilterMode Then TheSheet.ShowAllData
GetBottomRow = TheSheet.Cells.Find(what:="*", _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Exit Function
NoRow:
GetBottomRow = 0
End Function
'=======================================
'You can call the function like this...
Sub FindLastRowWithData()
Dim lngRw As Long
lngRw = GetBottomRow(ActiveSheet)
MsgBox lngRw
End Sub
'=======================================

Regards,
Jim Cone
San Francisco, CA

"m&m" wrote in message
...
Hi guys,
any Macro that can be written to detect the last row of data ?
please help



  #3   Report Post  
Posted to microsoft.public.excel.programming
m&m m&m is offline
external usenet poster
 
Posts: 3
Default detect last row of data

Thank you very much for your help indeed !!!

"Jim Cone" wrote in message
...
You are asking one of the most frequently asked questions in this

newsgroup.
A Google search will answer a lot of questions before you have to ask.

The following function usually works for me...

'=======================================
' GetBottomRow() Function
' Jim Cone did it
' Returns the number of the last worksheet row with data.
' If the sheet is blank it returns 0.
'=======================================
Function GetBottomRow(ByRef TheSheet as Worksheet) As Long
On Error GoTo NoRow
' Line below is optional. Also a check for hidden rows could be done

instead.
If TheSheet.FilterMode Then TheSheet.ShowAllData
GetBottomRow = TheSheet.Cells.Find(what:="*", _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Exit Function
NoRow:
GetBottomRow = 0
End Function
'=======================================
'You can call the function like this...
Sub FindLastRowWithData()
Dim lngRw As Long
lngRw = GetBottomRow(ActiveSheet)
MsgBox lngRw
End Sub
'=======================================

Regards,
Jim Cone
San Francisco, CA

"m&m" wrote in message
...
Hi guys,
any Macro that can be written to detect the last row of data ?
please help





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
need to detect syntax in value J.Parker Excel Discussion (Misc queries) 1 February 13th 10 05:09 AM
How to detect #N/A and return 0? Eric Excel Discussion (Misc queries) 2 May 30th 07 06:12 AM
How do I detect hidden worksheets or hidden data on a worksheet? Alice Excel Discussion (Misc queries) 4 August 24th 06 03:38 AM
how to detect 5th character? nastech Excel Discussion (Misc queries) 4 October 31st 05 11:31 AM
detect worksheet mike allen Excel Programming 2 October 28th 03 10:33 PM


All times are GMT +1. The time now is 11:33 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"