PC Review


Reply
Thread Tools Rate Thread

Determining the last row and column used on a sheet

 
 
John
Guest
Posts: n/a
 
      23rd Feb 2009
How can I quickly find the last used row and column of a worksheet?

I appreciate your help, -John
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      23rd Feb 2009

Use code like

Dim LastCell As Range
Dim WS As Worksheet
Set WS = ActiveSheet
Set LastCell = WS.UsedRange.SpecialCells(xlCellTypeLastCell)
Debug.Print LastCell.Address


Note, though, that this LastCell may not contain any data. It is in
the last row that has any data in it and in the last column that has
any data in it. E.g.,

X X
X X
X LC

Where X is data and LC is the LastCell, which may be empty.

If you need the last cell that has data, you need to decide whether
you want the right-most column or the highest-number row. For example,


X X X
X X 11
X
22


In this example, is 11 or 22 the last cell? It depends on what you are
looking for and what you need to accomplish with the last cell.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 23 Feb 2009 09:19:02 -0800, John
<(E-Mail Removed)> wrote:

>How can I quickly find the last used row and column of a worksheet?
>
>I appreciate your help, -John

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      23rd Feb 2009
Give these a try...

LastUsedRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlRows).Row

LastUsedColumn = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

--
Rick (MVP - Excel)


"John" <(E-Mail Removed)> wrote in message
news:C03E8D41-7C2E-4D8A-91CD-(E-Mail Removed)...
> How can I quickly find the last used row and column of a worksheet?
>
> I appreciate your help, -John


 
Reply With Quote
 
Maury Markowitz
Guest
Posts: n/a
 
      23rd Feb 2009
Be careful with UsedRange. The range inside gets expanded just by
talking to the cells even if there's nothing in it. I always use .Find
as a result.

Maury
 
Reply With Quote
 
Terry
Guest
Posts: n/a
 
      13th Apr 2010
This being the case, how does one "delete the last row, column entry" if a
cell was used erroneously? I keep getting a compatibilty error in 2007 from
a previous version, where the cell used was "outside" 255 X 65535.

"Maury Markowitz" wrote:

> Be careful with UsedRange. The range inside gets expanded just by
> talking to the cells even if there's nothing in it. I always use .Find
> as a result.
>
> Maury
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      13th Apr 2010
The way to avoid trying to do something with a blank cell, that you think
has data, is to test it with an If...Then statement. If it is not empty,
equal to zero or null then do something with it, else do nothiing.
Recognizing that xl2007 has considerably more rows and columns than previous
versions, all code from previous versions should be reviewed for possible
errors related to those differences.


"Terry" <(E-Mail Removed)> wrote in message
news:7E6DDC93-B66D-49F3-AA92-(E-Mail Removed)...
> This being the case, how does one "delete the last row, column entry" if a
> cell was used erroneously? I keep getting a compatibilty error in 2007
> from
> a previous version, where the cell used was "outside" 255 X 65535.
>
> "Maury Markowitz" wrote:
>
>> Be careful with UsedRange. The range inside gets expanded just by
>> talking to the cells even if there's nothing in it. I always use .Find
>> as a result.
>>
>> Maury
>>



 
Reply With Quote
 
Terry
Guest
Posts: n/a
 
      14th Apr 2010
Well I ran some code to delete any/all(hopefully) outside the normal area,
but still get the compatibility warning. After checking the last row/column
again now I find blank cells.

"JLGWhiz" wrote:

> The way to avoid trying to do something with a blank cell, that you think
> has data, is to test it with an If...Then statement. If it is not empty,
> equal to zero or null then do something with it, else do nothiing.
> Recognizing that xl2007 has considerably more rows and columns than previous
> versions, all code from previous versions should be reviewed for possible
> errors related to those differences.
>
>
> "Terry" <(E-Mail Removed)> wrote in message
> news:7E6DDC93-B66D-49F3-AA92-(E-Mail Removed)...
> > This being the case, how does one "delete the last row, column entry" if a
> > cell was used erroneously? I keep getting a compatibilty error in 2007
> > from
> > a previous version, where the cell used was "outside" 255 X 65535.
> >
> > "Maury Markowitz" wrote:
> >
> >> Be careful with UsedRange. The range inside gets expanded just by
> >> talking to the cells even if there's nothing in it. I always use .Find
> >> as a result.
> >>
> >> Maury
> >>

>
>
> .
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      14th Apr 2010
I am not running xl2007 so I am not familiar with the alerts unless they
apply to xl2003 as well. I don't recall seeing one in xl2003 regarding
compatibility. What exactly does it say and does the associated help file
provide any further information on possible causes?
Also, how is a normal area defined? I am having trouble visualizing the
problem.




"Terry" <(E-Mail Removed)> wrote in message
newsC2709A8-E08E-4F71-85B2-(E-Mail Removed)...
> Well I ran some code to delete any/all(hopefully) outside the normal area,
> but still get the compatibility warning. After checking the last
> row/column
> again now I find blank cells.
>
> "JLGWhiz" wrote:
>
>> The way to avoid trying to do something with a blank cell, that you think
>> has data, is to test it with an If...Then statement. If it is not empty,
>> equal to zero or null then do something with it, else do nothiing.
>> Recognizing that xl2007 has considerably more rows and columns than
>> previous
>> versions, all code from previous versions should be reviewed for possible
>> errors related to those differences.
>>
>>
>> "Terry" <(E-Mail Removed)> wrote in message
>> news:7E6DDC93-B66D-49F3-AA92-(E-Mail Removed)...
>> > This being the case, how does one "delete the last row, column entry"
>> > if a
>> > cell was used erroneously? I keep getting a compatibilty error in 2007
>> > from
>> > a previous version, where the cell used was "outside" 255 X 65535.
>> >
>> > "Maury Markowitz" wrote:
>> >
>> >> Be careful with UsedRange. The range inside gets expanded just by
>> >> talking to the cells even if there's nothing in it. I always use .Find
>> >> as a result.
>> >>
>> >> Maury
>> >>

>>
>>
>> .
>>



 
Reply With Quote
 
Terry
Guest
Posts: n/a
 
      14th Apr 2010
Column A-T rows 1-33, the error goes like this:
Some cells or stlyes in this workbook contain formatting that is not
supported by the selected file format(97-2003). These formats will be
converted to closest format available.
The help file discusses cells the old size 256 X 65536 and many other
topics. After using the code to eliminate entries "WAY" outside find now the
"last" cell AT42.
No other format, style or formula looks out of what 97 used to contain.
There are 150 sheets in the file.
I hope this better explains what I have.

"JLGWhiz" wrote:

> I am not running xl2007 so I am not familiar with the alerts unless they
> apply to xl2003 as well. I don't recall seeing one in xl2003 regarding
> compatibility. What exactly does it say and does the associated help file
> provide any further information on possible causes?
> Also, how is a normal area defined? I am having trouble visualizing the
> problem.
>
>
>
>
> "Terry" <(E-Mail Removed)> wrote in message
> newsC2709A8-E08E-4F71-85B2-(E-Mail Removed)...
> > Well I ran some code to delete any/all(hopefully) outside the normal area,
> > but still get the compatibility warning. After checking the last
> > row/column
> > again now I find blank cells.
> >
> > "JLGWhiz" wrote:
> >
> >> The way to avoid trying to do something with a blank cell, that you think
> >> has data, is to test it with an If...Then statement. If it is not empty,
> >> equal to zero or null then do something with it, else do nothiing.
> >> Recognizing that xl2007 has considerably more rows and columns than
> >> previous
> >> versions, all code from previous versions should be reviewed for possible
> >> errors related to those differences.
> >>
> >>
> >> "Terry" <(E-Mail Removed)> wrote in message
> >> news:7E6DDC93-B66D-49F3-AA92-(E-Mail Removed)...
> >> > This being the case, how does one "delete the last row, column entry"
> >> > if a
> >> > cell was used erroneously? I keep getting a compatibilty error in 2007
> >> > from
> >> > a previous version, where the cell used was "outside" 255 X 65535.
> >> >
> >> > "Maury Markowitz" wrote:
> >> >
> >> >> Be careful with UsedRange. The range inside gets expanded just by
> >> >> talking to the cells even if there's nothing in it. I always use .Find
> >> >> as a result.
> >> >>
> >> >> Maury
> >> >>
> >>
> >>
> >> .
> >>

>
>
> .
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      14th Apr 2010
I do not run xl2007 but here is a site that might help you.

http://blogs.msdn.com/excel/archive/...11/694891.aspx



"Terry" <(E-Mail Removed)> wrote in message
news:102E8ECB-D87A-4C57-92D4-(E-Mail Removed)...
> Column A-T rows 1-33, the error goes like this:
> Some cells or stlyes in this workbook contain formatting that is not
> supported by the selected file format(97-2003). These formats will be
> converted to closest format available.
> The help file discusses cells the old size 256 X 65536 and many other
> topics. After using the code to eliminate entries "WAY" outside find now
> the
> "last" cell AT42.
> No other format, style or formula looks out of what 97 used to contain.
> There are 150 sheets in the file.
> I hope this better explains what I have.
>
> "JLGWhiz" wrote:
>
>> I am not running xl2007 so I am not familiar with the alerts unless they
>> apply to xl2003 as well. I don't recall seeing one in xl2003 regarding
>> compatibility. What exactly does it say and does the associated help
>> file
>> provide any further information on possible causes?
>> Also, how is a normal area defined? I am having trouble visualizing the
>> problem.
>>
>>
>>
>>
>> "Terry" <(E-Mail Removed)> wrote in message
>> newsC2709A8-E08E-4F71-85B2-(E-Mail Removed)...
>> > Well I ran some code to delete any/all(hopefully) outside the normal
>> > area,
>> > but still get the compatibility warning. After checking the last
>> > row/column
>> > again now I find blank cells.
>> >
>> > "JLGWhiz" wrote:
>> >
>> >> The way to avoid trying to do something with a blank cell, that you
>> >> think
>> >> has data, is to test it with an If...Then statement. If it is not
>> >> empty,
>> >> equal to zero or null then do something with it, else do nothiing.
>> >> Recognizing that xl2007 has considerably more rows and columns than
>> >> previous
>> >> versions, all code from previous versions should be reviewed for
>> >> possible
>> >> errors related to those differences.
>> >>
>> >>
>> >> "Terry" <(E-Mail Removed)> wrote in message
>> >> news:7E6DDC93-B66D-49F3-AA92-(E-Mail Removed)...
>> >> > This being the case, how does one "delete the last row, column
>> >> > entry"
>> >> > if a
>> >> > cell was used erroneously? I keep getting a compatibilty error in
>> >> > 2007
>> >> > from
>> >> > a previous version, where the cell used was "outside" 255 X 65535.
>> >> >
>> >> > "Maury Markowitz" wrote:
>> >> >
>> >> >> Be careful with UsedRange. The range inside gets expanded just by
>> >> >> talking to the cells even if there's nothing in it. I always use
>> >> >> .Find
>> >> >> as a result.
>> >> >>
>> >> >> Maury
>> >> >>
>> >>
>> >>
>> >> .
>> >>

>>
>>
>> .
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare sheet 1 column A numbers with sheet 2 column A number Not and Excel Expert Microsoft Excel Worksheet Functions 2 7th Aug 2009 12:36 AM
Programmatically determining if a sheet is empty cullenmorris@gmail.com Microsoft Excel Programming 1 17th Jun 2008 10:11 PM
Determining Column Number from Column Name Jeff Microsoft VB .NET 3 24th Dec 2006 04:08 PM
Formula if Column E in Sheet 1 equals Column M in sheet 2, = Colum =?Utf-8?B?SnVhbg==?= Microsoft Excel Programming 0 23rd Aug 2006 10:15 PM
Programmatically determining CODE NAME for sheet based upon Sheet =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 14 15th Aug 2006 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:55 AM.