Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel hangs when switching focus

Hi,

I noticed that Excel 2007 (or VBA) hangs on a long-during VBA script when I switch focus between the VBA editor window and the Excel window.


I've written a small Sub to delete rows containing strings having a substring matching the row's above. The worksheet contains about 135,000 rows.

Just want to mention BTW that Excel takes about 1 sec. to delete 10 rows, which is incredibly slow!


While my script executed, just out of curiosity I wanted to switch to the Excel window to see how far it got. From that moment on both, Excel and VBA window, hung. I can't even pause anymore. I can't tell if my script still is running or if it hangs as well.

To me this seems to be a bug. So I'd like to know if anyone can reproduce this behaviour so I can open an issue with MS.

TIA,
Axel Dahmen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Excel hangs when switching focus

It is alway quicker to delete multiple cells at one time. I found by adding
a 1 to an auxilary column to indicate what rows you want to delete. Then
sorting on the column and deleting all the ones at one time reduces the time
it takes to delete rows. It take the same time to delete 100 rows at it
would to delete one row. If you don't want to sort, the use an autofilter on
the ones columns and delete the visible cells.

"Axel Dahmen" wrote:

Hi,

I noticed that Excel 2007 (or VBA) hangs on a long-during VBA script when
I switch focus between the VBA editor window and the Excel window.


I've written a small Sub to delete rows containing strings having a
substring matching the row's above. The worksheet contains about 135,000
rows.

Just want to mention BTW that Excel takes about 1 sec. to delete 10 rows,
which is incredibly slow!


While my script executed, just out of curiosity I wanted to switch to the
Excel window to see how far it got. From that moment on both, Excel and
VBA window, hung. I can't even pause anymore. I can't tell if my script
still is running or if it hangs as well.

To me this seems to be a bug. So I'd like to know if anyone can reproduce
this behaviour so I can open an issue with MS.

TIA,
Axel Dahmen

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel hangs when switching focus

Thanks Joel, I see...

I just checked and saw that it doesn't actually take 1 sec. to *delete* 10 rows, but just to *iterate* through them. Nothing has been deleted so far because I used a wrong variable in my code.

The hanging also seems only to occur when *nothing* is actually changed. After I've corrected my script to actually delete double rows I can now switch between both windows.

Still the hanging shouldn't occur if the Worksheet isn't updated though.

Can you reproduce the hanging?

TIA,
Axel Dahmen


Here's the code I've been using:

----------
Option Explicit

Sub DelDoubles()
Dim y&
Dim s1$, s2$, p1$, p2$, f1$, f2$
Dim pos1%, pos2%
Dim ws As Worksheet

Set ws = ActiveSheet
For y = ws.UsedRange.Rows.Count - 1 To 1 Step -1

' find last backslash
s1 = ws.UsedRange.Cells(y, 1)
s2 = ws.UsedRange.Cells(y + 1, 1)

' do both paths match?
p1 = Left$(s1, InStrRev(s1, "\") - 1)
p2 = Left$(s2, InStrRev(s2, "\") - 1)
f1 = Mid$(s1, Len(p1) + 1)
f2 = Mid$(s2, Len(p2) + 1)
pos1 = InStrRev(f1, ".")
pos2 = InStrRev(f2, ".")

If p1 = p2 And pos1 0 And pos2 0 Then
' do both filepaths match and are file names equally long? Then delete second row.
If Mid$(f1, pos1) = Mid$(f2, pos2) And pos1 = pos2 Then ws.UsedRange.Rows(y + 1).Delete
End If
Next
End Sub



-----------------
"Joel" schrieb im Newsbeitrag ...
It is alway quicker to delete multiple cells at one time. I found by adding
a 1 to an auxilary column to indicate what rows you want to delete. Then
sorting on the column and deleting all the ones at one time reduces the time
it takes to delete rows. It take the same time to delete 100 rows at it
would to delete one row. If you don't want to sort, the use an autofilter on
the ones columns and delete the visible cells.

"Axel Dahmen" wrote:

Hi,

I noticed that Excel 2007 (or VBA) hangs on a long-during VBA script when
I switch focus between the VBA editor window and the Excel window.


I've written a small Sub to delete rows containing strings having a
substring matching the row's above. The worksheet contains about 135,000
rows.

Just want to mention BTW that Excel takes about 1 sec. to delete 10 rows,
which is incredibly slow!


While my script executed, just out of curiosity I wanted to switch to the
Excel window to see how far it got. From that moment on both, Excel and
VBA window, hung. I can't even pause anymore. I can't tell if my script
still is running or if it hangs as well.

To me this seems to be a bug. So I'd like to know if anyone can reproduce
this behaviour so I can open an issue with MS.

TIA,
Axel Dahmen

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
Excel hangs on calculation snobordr New Users to Excel 2 July 8th 06 11:25 AM
Excel hangs... coder_arun Excel Programming 2 April 25th 06 01:46 PM
Excel hangs up. bc Excel Discussion (Misc queries) 0 February 28th 06 06:30 PM
Excel hangs Oxns Excel Programming 9 February 24th 06 05:32 AM
Excel Hangs Linda Excel Discussion (Misc queries) 2 October 4th 05 04:36 PM


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