PC Review


Reply
Thread Tools Rate Thread

Can Turn Off Internal "Undo" Stack in VBA?

 
 
Larry Adams
Guest
Posts: n/a
 
      19th Apr 2007
I have an apllication where I examine 5500 rows to see if empty and, if so,
"Hide" the row. Otherwise, "Unhide". After this macro has been run a few
times, the macro slows to a crawl.

My hypothesis is that Excel's internal "Undo" feature is tracking these
changes and I am filling up memory set aside for "Undo"s -- which, then
causes Excel to clear the oldest entry in the stack in order to add the
next. At which point it crawls.

I've seen this outside of VBA in Exel proper when I go to do a "Find and
Replace All" on a large data retrieval area. The replace zips along fine,
then slows, then crawls.

I'm wondering if my VBA "Unhide"/"Hide" code is running into something
similar. Hope I've described the symptoms well enough. Any ideas would be
welcome. Thanks.


 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      19th Apr 2007
I'm not sure what causes the slowdown in most cases, but I suspect that,
since macros clear XL's Undo stack, it isn't the culprit.

In article <#(E-Mail Removed)>,
"Larry Adams" <(E-Mail Removed)> wrote:

> I have an apllication where I examine 5500 rows to see if empty and, if so,
> "Hide" the row. Otherwise, "Unhide". After this macro has been run a few
> times, the macro slows to a crawl.
>
> My hypothesis is that Excel's internal "Undo" feature is tracking these
> changes and I am filling up memory set aside for "Undo"s -- which, then
> causes Excel to clear the oldest entry in the stack in order to add the
> next. At which point it crawls.
>
> I've seen this outside of VBA in Exel proper when I go to do a "Find and
> Replace All" on a large data retrieval area. The replace zips along fine,
> then slows, then crawls.
>
> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
> similar. Hope I've described the symptoms well enough. Any ideas would be
> welcome. Thanks.

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      19th Apr 2007
Does your macro use Find() ?

In my experience it may not be as fast as you expect: sometimes there are
other faster approaches.
Maybe you could show your code?

Tim


"Larry Adams" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have an apllication where I examine 5500 rows to see if empty and, if so,
>"Hide" the row. Otherwise, "Unhide". After this macro has been run a few
>times, the macro slows to a crawl.
>
> My hypothesis is that Excel's internal "Undo" feature is tracking these
> changes and I am filling up memory set aside for "Undo"s -- which, then
> causes Excel to clear the oldest entry in the stack in order to add the
> next. At which point it crawls.
>
> I've seen this outside of VBA in Exel proper when I go to do a "Find and
> Replace All" on a large data retrieval area. The replace zips along fine,
> then slows, then crawls.
>
> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
> similar. Hope I've described the symptoms well enough. Any ideas would
> be welcome. Thanks.
>



 
Reply With Quote
 
Larry Adams
Guest
Posts: n/a
 
      19th Apr 2007
No, the find was an external example of the same type of slowdown I am
getting here. All I am doing here is to examine a cell on each of the 5500
rows and, if "1", unhide the row, a "0", hide. Below is the code.

The slow down occurs within the loop. If I <CTRL><BREAK> and debug, I can
check the i loop value. Normally slows arounf 800 or so. If I continue the
macro and interrupt again, the i counter is increasing, so I know I am not
totally locked. Just slow. Thanks.

Sub A20_DeptShowNonZero() '### Starts with Active Cell ###
Dim i, j, curr_lvl, next_lvl As Integer
Dim c, row As String
application.ScreenUpdating = False
Worksheets("DEPT").Activate
c = ActiveCell.Address
row = ActiveCell.row
With Worksheets("DEPT").range("D" & row)
curr_lvl = .Offset(0, -3)
For i = 1 To 20000
If .Offset(i, 0) = "" Then
Exit For
End If
next_lvl = .Offset(i, -3)
If next_lvl <= curr_lvl Then
Exit For
Else
Rows("" & (row + i) & ":" & (row + i) & "").Select
If .Offset(i, 13) = 1 Then
selection.EntireRow.Hidden = False
Else
selection.EntireRow.Hidden = True
End If
End If
Next i
End With
Worksheets("DEPT").range(c).Select
End Sub


"Tim Williams" <timjwilliams at gmail dot com> wrote in message
news:(E-Mail Removed)...
> Does your macro use Find() ?
>
> In my experience it may not be as fast as you expect: sometimes there are
> other faster approaches.
> Maybe you could show your code?
>
> Tim
>
>
> "Larry Adams" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>>I have an apllication where I examine 5500 rows to see if empty and, if
>>so, "Hide" the row. Otherwise, "Unhide". After this macro has been run a
>>few times, the macro slows to a crawl.
>>
>> My hypothesis is that Excel's internal "Undo" feature is tracking these
>> changes and I am filling up memory set aside for "Undo"s -- which, then
>> causes Excel to clear the oldest entry in the stack in order to add the
>> next. At which point it crawls.
>>
>> I've seen this outside of VBA in Exel proper when I go to do a "Find and
>> Replace All" on a large data retrieval area. The replace zips along
>> fine, then slows, then crawls.
>>
>> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
>> similar. Hope I've described the symptoms well enough. Any ideas would
>> be welcome. Thanks.
>>

>
>



 
Reply With Quote
 
Larry Adams
Guest
Posts: n/a
 
      19th Apr 2007
Per a Google search, I saw where Excel does clear the stack on the first
change to a sheet. I'm wondering, however, if that may be on the first
change to a cell -- and maybe not hide/unhide rows.

So I'm rewriting the code to hide/unhide contiguous rows together in one
statement, rather than one at a time. Will pass out to people at work today
to try and see how it goes. But it is stop gap only.

So the other thought is to throw in an innoculous cell change.

But if this has nothing to do with the undo stack, I still have a problem.
I've included code now under the other reply. Thanks again.


"JE McGimpsey" <(E-Mail Removed)> wrote in message
news:jemcgimpsey-(E-Mail Removed)...
> I'm not sure what causes the slowdown in most cases, but I suspect that,
> since macros clear XL's Undo stack, it isn't the culprit.
>
> In article <#(E-Mail Removed)>,
> "Larry Adams" <(E-Mail Removed)> wrote:
>
>> I have an apllication where I examine 5500 rows to see if empty and, if
>> so,
>> "Hide" the row. Otherwise, "Unhide". After this macro has been run a
>> few
>> times, the macro slows to a crawl.
>>
>> My hypothesis is that Excel's internal "Undo" feature is tracking these
>> changes and I am filling up memory set aside for "Undo"s -- which, then
>> causes Excel to clear the oldest entry in the stack in order to add the
>> next. At which point it crawls.
>>
>> I've seen this outside of VBA in Exel proper when I go to do a "Find and
>> Replace All" on a large data retrieval area. The replace zips along
>> fine,
>> then slows, then crawls.
>>
>> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
>> similar. Hope I've described the symptoms well enough. Any ideas would
>> be
>> welcome. Thanks.



 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      19th Apr 2007
just a not-a-guru idea...........
since you suspect that the stack gets cleared on the first change to a
cell, why don't you try adding some sort of a change to a cell @ the
bottom of your macro?

such as (i know syntax may not be correct):

worksheet.range("xx2") = "327"
worksheet.range("xx2").clearcontents

maybe that would clear the stack so then it can be run again as the
first time?
just an idea.

susan


On Apr 19, 7:22 am, "Larry Adams" <lad...@columbus.rr.com> wrote:
> Per a Google search, I saw where Excel does clear the stack on the first
> change to a sheet. I'm wondering, however, if that may be on the first
> change to a cell -- and maybe not hide/unhide rows.
>
> So I'm rewriting the code to hide/unhide contiguous rows together in one
> statement, rather than one at a time. Will pass out to people at work today
> to try and see how it goes. But it is stop gap only.
>
> So the other thought is to throw in an innoculous cell change.
>
> But if this has nothing to do with the undo stack, I still have a problem.
> I've included code now under the other reply. Thanks again.
>
> "JE McGimpsey" <jemcgimp...@mvps.org> wrote in message
>
> news:jemcgimpsey-(E-Mail Removed)...
>
>
>
> > I'm not sure what causes the slowdown in most cases, but I suspect that,
> > since macros clear XL's Undo stack, it isn't the culprit.

>
> > In article <#yRaDPjgHHA.4...@TK2MSFTNGP03.phx.gbl>,
> > "Larry Adams" <lad...@columbus.rr.com> wrote:

>
> >> I have an apllication where I examine 5500 rows to see if empty and, if
> >> so,
> >> "Hide" the row. Otherwise, "Unhide". After this macro has been run a
> >> few
> >> times, the macro slows to a crawl.

>
> >> My hypothesis is that Excel's internal "Undo" feature is tracking these
> >> changes and I am filling up memory set aside for "Undo"s -- which, then
> >> causes Excel to clear the oldest entry in the stack in order to add the
> >> next. At which point it crawls.

>
> >> I've seen this outside of VBA in Exel proper when I go to do a "Find and
> >> Replace All" on a large data retrieval area. The replace zips along
> >> fine,
> >> then slows, then crawls.

>
> >> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
> >> similar. Hope I've described the symptoms well enough. Any ideas would
> >> be
> >> welcome. Thanks.- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      19th Apr 2007
On Apr 19, 7:22 am, "Larry Adams" <lad...@columbus.rr.com> wrote:
>So the other thought is to throw in an innoculous cell change


duh. see, i thought it was a good idea!

that'll teach me to read more carefully before i throw out an idea.
susan

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Apr 2007
(Saved from a previous post)

Do you see the dotted lines that you get after you do a print or print preview?

If you do
Tools|Options|view tab|uncheck display page breaks

does the run time go back to normal?

You may want to do something like:

Option Explicit
Sub testme()

Dim CalcMode As Long
Dim ViewMode As Long

Application.ScreenUpdating = False

CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

ActiveSheet.DisplayPageBreaks = False

'do the work

'put things back to what they were
Application.Calculation = CalcMode
ActiveWindow.View = ViewMode

End Sub

Being in View|PageBreak Preview mode can slow macros down, too.

Larry Adams wrote:
>
> I have an apllication where I examine 5500 rows to see if empty and, if so,
> "Hide" the row. Otherwise, "Unhide". After this macro has been run a few
> times, the macro slows to a crawl.
>
> My hypothesis is that Excel's internal "Undo" feature is tracking these
> changes and I am filling up memory set aside for "Undo"s -- which, then
> causes Excel to clear the oldest entry in the stack in order to add the
> next. At which point it crawls.
>
> I've seen this outside of VBA in Exel proper when I go to do a "Find and
> Replace All" on a large data retrieval area. The replace zips along fine,
> then slows, then crawls.
>
> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
> similar. Hope I've described the symptoms well enough. Any ideas would be
> welcome. Thanks.


--

Dave Peterson
 
Reply With Quote
 
Larry Adams
Guest
Posts: n/a
 
      20th Apr 2007
Susan, still appreciate the thought. The code suggested by the site I found
is fairly generic -- and seems to be helping. Thanks.

Sub ClearUndo()
Range("A1").copy Range("A1")
End Sub

"Susan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Apr 19, 7:22 am, "Larry Adams" <lad...@columbus.rr.com> wrote:
>>So the other thought is to throw in an innoculous cell change

>
> duh. see, i thought it was a good idea!
>
> that'll teach me to read more carefully before i throw out an idea.
> susan
>



 
Reply With Quote
 
Larry Adams
Guest
Posts: n/a
 
      20th Apr 2007
Dave, I think you've identified a factor with this as well. As the page is
formatted to print to fit -- across all 5500 rows, with the assumption that
there will normally be no more that 50 or so left unhidden. But I start
with 5500 rows unhidden, and pull out one line at a time.

I will look into. Thanks!!

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (Saved from a previous post)
>
> Do you see the dotted lines that you get after you do a print or print
> preview?
>
> If you do
> Tools|Options|view tab|uncheck display page breaks
>
> does the run time go back to normal?
>
> You may want to do something like:
>
> Option Explicit
> Sub testme()
>
> Dim CalcMode As Long
> Dim ViewMode As Long
>
> Application.ScreenUpdating = False
>
> CalcMode = Application.Calculation
> Application.Calculation = xlCalculationManual
>
> ViewMode = ActiveWindow.View
> ActiveWindow.View = xlNormalView
>
> ActiveSheet.DisplayPageBreaks = False
>
> 'do the work
>
> 'put things back to what they were
> Application.Calculation = CalcMode
> ActiveWindow.View = ViewMode
>
> End Sub
>
> Being in View|PageBreak Preview mode can slow macros down, too.
>
> Larry Adams wrote:
>>
>> I have an apllication where I examine 5500 rows to see if empty and, if
>> so,
>> "Hide" the row. Otherwise, "Unhide". After this macro has been run a
>> few
>> times, the macro slows to a crawl.
>>
>> My hypothesis is that Excel's internal "Undo" feature is tracking these
>> changes and I am filling up memory set aside for "Undo"s -- which, then
>> causes Excel to clear the oldest entry in the stack in order to add the
>> next. At which point it crawls.
>>
>> I've seen this outside of VBA in Exel proper when I go to do a "Find and
>> Replace All" on a large data retrieval area. The replace zips along
>> fine,
>> then slows, then crawls.
>>
>> I'm wondering if my VBA "Unhide"/"Hide" code is running into something
>> similar. Hope I've described the symptoms well enough. Any ideas would
>> be
>> welcome. Thanks.

>
> --
>
> Dave Peterson



 
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
"Undo" and "Redo" are suddenly grayed out jenmusca Microsoft Word Document Management 2 10th Jun 2009 10:05 PM
Power Mgt: "Turn off monitor" "Never" always reverts to "After 20 mins" OpaPiloot Windows XP Video 2 18th Jul 2008 08:16 PM
No "Standby" available when "START>TURN OFF COMPUTER" selected - K8VSE Deluxe m/b admiral_victory@iol.ie Asus Motherboards 9 1st Jan 2005 01:54 PM
How to "turn off" automatic sending (create "send only" accts) Steve Hurd Microsoft Outlook 2 6th Mar 2004 04:10 PM
How do we normally implement "Undo"/"Redo" function? babylon Microsoft C# .NET 3 9th Jan 2004 09:02 AM


Features
 

Advertising
 

Newsgroups
 


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