Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default How to get the last row in a column without selecting

Hi,

My aim is to get the last populated row in a column. I successfully use this
function.

Function fncLastRowCo(ColID As Long) As Long
'Returns the row number of the last row in the ColID-th column
Dim n As Long

Cells(1, 1).Select
ActiveCell.SpecialCells(xlLastCell).Select
n = ActiveCell.Row
Cells(n, ColID).Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
fncLastRowCo = Selection.Row
End Function

Now I need to write a user defined function that can get the last row in a
column in any worksheet.
When one uses the function in E.g. Sheet2 and one needs to get the data from
Sheet5 the methode above is not possible since it is not possible to leave
the sheet on which the User Defined function is located, while running it.

Any ideas?

Thanks!

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to get the last row in a column without selecting

Try this one-liner...

LastUsedRowInCol4= Worksheets("Sheet5").Cells(Rows.Count, 4).End(xlUp).Row

Rick


"Michiel via OfficeKB.com" <u40062@uwe wrote in message
news:7f4b719872d1e@uwe...
Hi,

My aim is to get the last populated row in a column. I successfully use
this
function.

Function fncLastRowCo(ColID As Long) As Long
'Returns the row number of the last row in the ColID-th column
Dim n As Long

Cells(1, 1).Select
ActiveCell.SpecialCells(xlLastCell).Select
n = ActiveCell.Row
Cells(n, ColID).Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
fncLastRowCo = Selection.Row
End Function

Now I need to write a user defined function that can get the last row in a
column in any worksheet.
When one uses the function in E.g. Sheet2 and one needs to get the data
from
Sheet5 the methode above is not possible since it is not possible to leave
the sheet on which the User Defined function is located, while running it.

Any ideas?

Thanks!

--
Message posted via http://www.officekb.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default How to get the last row in a column without selecting

Rick you are a genious!
Thanks!


Rick Rothstein (MVP - VB) wrote:
Try this one-liner...

LastUsedRowInCol4= Worksheets("Sheet5").Cells(Rows.Count, 4).End(xlUp).Row

Rick


--
Message posted via http://www.officekb.com

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
Text to column and selecting values based on a different column torooo Excel Worksheet Functions 5 October 21st 06 03:35 PM
Text to column and selecting values based on a different column [email protected] Excel Worksheet Functions 1 October 21st 06 03:10 AM
Text to column and selecting values based on a different column torooo Excel Discussion (Misc queries) 1 October 18th 06 07:27 PM
selecting a column James Cornthwaite Excel Programming 8 June 14th 06 10:20 AM
Selecting to end of column Robbyn[_2_] Excel Programming 0 January 7th 04 01:01 AM


All times are GMT +1. The time now is 07:15 AM.

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

About Us

"It's about Microsoft Excel"