Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Here's a simple routine for LastRow, LastColumn

I put together a simple routine that will find the last Row and last Column w/ data in a spreadsheet
Without the pitfalls and limitations of
End(xlup), End(xlDown) and "simple" UsedRange
Any critique is welcomed

Sub LstRow_LstColumn(
Dim Rw As Range, Clm As Rang
Dim x As Single, LRw As Single, LClm As Singl

If WorksheetFunction.CountA(ActiveSheet.UsedRange) = 0 Then Exit Su
With ActiveSheet.UsedRange
D
x = x +
Set Rw = .Offset(.Rows.Count - x).Resize(1
Loop Until WorksheetFunction.CountA(Rw) <
LRw = Rw.Ro
x =
D
x = x +
Set Clm = .Offset(0, .Columns.Count - x).Resize(, 1
Loop Until WorksheetFunction.CountA(Clm) <
LClm = Clm.Colum
End Wit
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Here's a simple routine for LastRow, LastColumn

chris a écrit :
I put together a simple routine that will find the last Row and last Column w/ data in a spreadsheet.
Without the pitfalls and limitations of:
End(xlup), End(xlDown) and "simple" UsedRange.
Any critique is welcomed.

Sub LstRow_LstColumn()
Dim Rw As Range, Clm As Range
Dim x As Single, LRw As Single, LClm As Single

If WorksheetFunction.CountA(ActiveSheet.UsedRange) = 0 Then Exit Sub
With ActiveSheet.UsedRange
Do
x = x + 1
Set Rw = .Offset(.Rows.Count - x).Resize(1)
Loop Until WorksheetFunction.CountA(Rw) < 0
LRw = Rw.Row
x = 0
Do
x = x + 1
Set Clm = .Offset(0, .Columns.Count - x).Resize(, 1)
Loop Until WorksheetFunction.CountA(Clm) < 0
LClm = Clm.Column
End With
End Sub



Hi Chris,

I use these to find out :
* last row
Lx = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row

* last column
Cx = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column

The very last cell as address (sheet starting in A1) :
MsgBox Cells(Lx, Cx).Address

HTH
@+
FxM
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Here's a simple routine for LastRow, LastColumn

"FxM" wrote in message
...

I use these to find out :


Lx = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row


Apart from the nasty [A1], which can be circumvented by Range("A1"), I like
that. It doesn't however improve IMO upon

Cells(Rows.Count,"A").End(xlUp).Row


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Here's a simple routine for LastRow, LastColumn

Hi Bob

Not sure that the final goal is the same.
Consider one sheet with only range("G5") filled in :

Sub test()
k = Cells(Rows.Count, "A").End(xlUp).Row
Lx = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
End Sub

returns
k = 1 (because nothing in column A)
Lx = 5 ('lowest' row of any column)

@+
FxM
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Here's a simple routine for LastRow, LastColumn

When writing a program to Reset the UsedRange, I have tried everything known
to man under the sun. From lots of testing, I have found that using "Find"
as others have mentioned is the fastest way to do it.
Keep in mind that a Cell Note may contain useful information that is
"Outside" this "last cell" if using this to deleting anything.

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Bob Phillips" wrote in message
...
"FxM" wrote in message
...

I use these to find out :


Lx = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row


Apart from the nasty [A1], which can be circumvented by Range("A1"), I

like
that. It doesn't however improve IMO upon

Cells(Rows.Count,"A").End(xlUp).Row






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Here's a simple routine for LastRow, LastColumn

Hi

You can use find
See the functions I use in this example
http://www.rondebruin.nl/copy1.htm


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


"chris" wrote in message ...
I put together a simple routine that will find the last Row and last Column w/ data in a spreadsheet.
Without the pitfalls and limitations of:
End(xlup), End(xlDown) and "simple" UsedRange.
Any critique is welcomed.

Sub LstRow_LstColumn()
Dim Rw As Range, Clm As Range
Dim x As Single, LRw As Single, LClm As Single

If WorksheetFunction.CountA(ActiveSheet.UsedRange) = 0 Then Exit Sub
With ActiveSheet.UsedRange
Do
x = x + 1
Set Rw = .Offset(.Rows.Count - x).Resize(1)
Loop Until WorksheetFunction.CountA(Rw) < 0
LRw = Rw.Row
x = 0
Do
x = x + 1
Set Clm = .Offset(0, .Columns.Count - x).Resize(, 1)
Loop Until WorksheetFunction.CountA(Clm) < 0
LClm = Clm.Column
End With
End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Here's a simple routine for LastRow, LastColumn

and the limitations of End(xlUP) and End(xlDown) are ...?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"chris" wrote in message
...
I put together a simple routine that will find the last Row and last

Column w/ data in a spreadsheet.
Without the pitfalls and limitations of:
End(xlup), End(xlDown) and "simple" UsedRange.
Any critique is welcomed.

Sub LstRow_LstColumn()
Dim Rw As Range, Clm As Range
Dim x As Single, LRw As Single, LClm As Single

If WorksheetFunction.CountA(ActiveSheet.UsedRange) = 0 Then Exit Sub
With ActiveSheet.UsedRange
Do
x = x + 1
Set Rw = .Offset(.Rows.Count - x).Resize(1)
Loop Until WorksheetFunction.CountA(Rw) < 0
LRw = Rw.Row
x = 0
Do
x = x + 1
Set Clm = .Offset(0, .Columns.Count - x).Resize(, 1)
Loop Until WorksheetFunction.CountA(Clm) < 0
LClm = Clm.Column
End With
End Sub



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 Mr. Damon[_2_] Excel Worksheet Functions 3 July 30th 08 04:12 PM
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
LastRow issue Anne[_4_] Excel Programming 3 October 31st 03 02:06 AM


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