If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > UsedRange problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-08, 05:39
michaeldavid michaeldavid is offline
Registered User
 
Join Date: Dec 2004
Posts: 35
UsedRange problem

Hi,

I have been using the extension 'UsedRange.Rows.Count' to find the last row used on a worksheet for longer than I care to remember and have today found a problem.

I generally produce worksheets that start at Row1, but today had reason to start at Row10.
The code I have always used to loop from the first to the last line for a worksheet set to ShtName is

For Looper = 1 to ShtName.UsedRange.Rows.Count

Imagine my surprise when this stopped 10 lines short of the end. Has anyone else come across this problem and how have they solved it? Is there a way of getting the number of the final row used in a worksheet? I have got around this by inserting a value in cell A1 at the start of the module and then removing it at the end of the module, but this seems to be cheating.

Any help would be appreciated.
Mike
Reply With Quote
  #2 (permalink)  
Old 11-18-08, 05:49
michaeldavid michaeldavid is offline
Registered User
 
Join Date: Dec 2004
Posts: 35
Maybe the answer

Just found 'UsedRange.End(xlDown).Row'

Is this the answer or will this give me problems in the future?

Also found

ShtName.UsedRange.Rows.Count + ShtName.UsedRange.Row-1

Ths looks to be a better answer

Last edited by michaeldavid; 11-18-08 at 06:58.
Reply With Quote
  #3 (permalink)  
Old 11-23-08, 17:45
pierrevbaexcel pierrevbaexcel is offline
Registered User
 
Join Date: Dec 2003
Location: Ottawa, Canada
Posts: 72
Hi

ActiveSheet.UsedRange.Range("A1").Row + ActiveSheet.UsedRange.Rows.Count - 1

But I prefer using CurrentRegion when I work with database extracts
__________________
A piece of data is like a brick
If you don't build anything with it
It is just a brick
www.excel-examples.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On