Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Used Rows Range?

I've used the code below that was suggested to delete all of the old
data from a worksheet and hopefully reset the UsedRange back to just the
height of the header row but when I check the UsedRange of the worksheet I
still get 65536 as the used rows. Hence when I try to loop through my code
it tries to test all 65536 Rows. IDEAS? Here is the code below.

I only want to test the used range of the worksheet, I can't test for a
blank row since many exist in the document. I just need the last row of
data.


First_Row = 3
Application.Worksheets("Work Sheet").Rows(First_Row).Resize(65536 -
First_Row).EntireRow.Delete

Debug.Print Application.Worksheets("Work Sheet").Rows.Count


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Used Rows Range?

641 is the right answer???


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Used Rows Range?

It is the right number of rows.

--
Regards,
Tom Ogilvy


"HotRod" wrote in message
...
641 is the right answer???




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Used Rows Range?

Why in the following example do I get two differnet answers. Whats the
difference between the two?


Set Rng = Worksheets("Main Sheet").UsedRange.Rows
Main_Sheet_Count = Worksheets("Main Sheet").UsedRange.Count

Debug.Print Main_Sheet_Count = 7692

Debug.Print Rng.Rows.Count = 641


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Used Rows Range?

Because you usedrange has multiple columns.

count is #rows x #columns

--
Regards,
Tom Ogilvy


"HotRod" wrote in message
...
Why in the following example do I get two differnet answers. Whats the
difference between the two?


Set Rng = Worksheets("Main Sheet").UsedRange.Rows
Main_Sheet_Count = Worksheets("Main Sheet").UsedRange.Count

Debug.Print Main_Sheet_Count = 7692

Debug.Print Rng.Rows.Count = 641






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Used Rows Range?

that alone doesn't reset the Usedrange. It is just required.

This worked for me:

Sub ResetUsed()
Debug.Print "Work sheet: " & Application. _
Worksheets("Work Sheet").UsedRange.Rows.Count

First_Row = 3
With Application.Worksheets("Work Sheet")
.Rows(First_Row + 1).Resize(65536 - _
First_Row).EntireRow.Delete
.UsedRange
End With

Debug.Print "Work sheet: " & Application. _
Worksheets("Work Sheet").UsedRange.Rows.Count

End Sub

this
? activesheet.rows.count
65536

always returns the total rows in a sheet which is always 65536 - it has
nothing to do with the used range.

--
Regards,
Tom Ogilvy



"HotRod" wrote in message
...
I've used the code below that was suggested to delete all of the old
data from a worksheet and hopefully reset the UsedRange back to just the
height of the header row but when I check the UsedRange of the worksheet I
still get 65536 as the used rows. Hence when I try to loop through my code
it tries to test all 65536 Rows. IDEAS? Here is the code below.

I only want to test the used range of the worksheet, I can't test for

a
blank row since many exist in the document. I just need the last row of
data.


First_Row = 3
Application.Worksheets("Work Sheet").Rows(First_Row).Resize(65536 -
First_Row).EntireRow.Delete

Debug.Print Application.Worksheets("Work Sheet").Rows.Count




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Used Rows Range?

Thanks Tom, your explanation explains a few things. GREAT


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
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
formula to sort a range so that it matches the exact rows of a column that is outside that range? steveo Excel Discussion (Misc queries) 1 June 18th 06 02:05 AM
Range of even/odd rows Cool Sport Excel Programming 1 February 2nd 05 08:13 AM
Rows in a Range John Smith[_12_] Excel Programming 3 November 14th 04 01:56 PM
group rows in a range based on criteria from another range (vba) Andy Excel Programming 2 April 28th 04 03:26 AM


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