Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Which is more efficient?

I'd like opinions on which is more efficient in a macro.

Problem: When using a pivot table, a macro needs to know
the last row. "ActiveSheet.Cells.SpecialCells
(xlCellTypeLastCell).Row" does not get updated when the
pivot table gets filtered. In other words, if the table
starts out at 2000 rows and then is filtered to 10 rows,
the SpecialCells value still says 2000. But after using
UsedRange, the SpecialCells value does get updated.

Which method do you think is more efficient:
1) ActiveSheet.UsedRange.Row +
ActiveSheet.UsedRange.Rows.Count

2) Range("A65536").End(xlUp).Row

Or any other thought on getting the last row of a pivot
table?

Thank You!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Which is more efficient?

Hi Norm,

I would always use

Range("A65536").End(xlUp).Row

or more specifically

Range("A" & Rows.Count).End(xlUp).Row

as that will always work. UsedRange does not always automatically update.

--

HTH

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

"Norm" wrote in message
...
I'd like opinions on which is more efficient in a macro.

Problem: When using a pivot table, a macro needs to know
the last row. "ActiveSheet.Cells.SpecialCells
(xlCellTypeLastCell).Row" does not get updated when the
pivot table gets filtered. In other words, if the table
starts out at 2000 rows and then is filtered to 10 rows,
the SpecialCells value still says 2000. But after using
UsedRange, the SpecialCells value does get updated.

Which method do you think is more efficient:
1) ActiveSheet.UsedRange.Row +
ActiveSheet.UsedRange.Rows.Count

2) Range("A65536").End(xlUp).Row

Or any other thought on getting the last row of a pivot
table?

Thank You!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Which is more efficient?

set rng = ActiveSheet.PivotTables(1).TableRange2

lastrow = rng.rows(rng.rows.count).row

xlCellTypeLastCell uses UsedRange, so if one doesn't meet your expectations,
neither will.

--
Regards,
Tom Ogilvy

"Norm" wrote in message
...
I'd like opinions on which is more efficient in a macro.

Problem: When using a pivot table, a macro needs to know
the last row. "ActiveSheet.Cells.SpecialCells
(xlCellTypeLastCell).Row" does not get updated when the
pivot table gets filtered. In other words, if the table
starts out at 2000 rows and then is filtered to 10 rows,
the SpecialCells value still says 2000. But after using
UsedRange, the SpecialCells value does get updated.

Which method do you think is more efficient:
1) ActiveSheet.UsedRange.Row +
ActiveSheet.UsedRange.Rows.Count

2) Range("A65536").End(xlUp).Row

Or any other thought on getting the last row of a pivot
table?

Thank You!!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Which is more efficient?

Or any other thought on getting the last row of a pivot
table?


Would this idea work independent of the Used Range?

Sub Demo()
With ActiveSheet.PivotTables(1).RowRange
MsgBox "Last Row: " & .Row + .Rows.Count - 1
End With
End Sub

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


"Bob Phillips" wrote in message
...
Hi Norm,

I would always use

Range("A65536").End(xlUp).Row

or more specifically

Range("A" & Rows.Count).End(xlUp).Row

as that will always work. UsedRange does not always automatically update.

--

HTH

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

"Norm" wrote in message
...
I'd like opinions on which is more efficient in a macro.

Problem: When using a pivot table, a macro needs to know
the last row. "ActiveSheet.Cells.SpecialCells
(xlCellTypeLastCell).Row" does not get updated when the
pivot table gets filtered. In other words, if the table
starts out at 2000 rows and then is filtered to 10 rows,
the SpecialCells value still says 2000. But after using
UsedRange, the SpecialCells value does get updated.

Which method do you think is more efficient:
1) ActiveSheet.UsedRange.Row +
ActiveSheet.UsedRange.Rows.Count

2) Range("A65536").End(xlUp).Row

Or any other thought on getting the last row of a pivot
table?

Thank You!!





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
What's themost efficient way Rod Excel Worksheet Functions 2 December 30th 08 09:31 PM
Efficient linking teh_chucksta Excel Discussion (Misc queries) 3 April 18th 08 11:44 PM
What is more efficient Brad Excel Discussion (Misc queries) 2 November 20th 06 09:13 PM
is there a more efficient formula than... Wazooli Excel Worksheet Functions 6 February 24th 05 06:39 PM
Is there more efficient formula? Diana[_5_] Excel Programming 19 August 22nd 03 10:24 PM


All times are GMT +1. The time now is 10:36 AM.

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

About Us

"It's about Microsoft Excel"