|
-
Jul 6th, 2006, 08:57 AM
#1
Thread Starter
New Member
Excel freezes when running code
I have written code for a macro, the first part of which looks at the whole worksheet (which has over 60 000 entries), prompts the user to enter a specific country name and then copies all the entries for that country in question into a separate worksheet. Here is the relevant part of that code:
Country = InputBox("Enter a country name")
NoClients = Application.WorksheetFunction.CountIf(Range("A:A"), "<>") - 1
For i = NoClients To 0 Step -1
If Cells(i + RowOffset, ColumnOffset) = Country Then
Rows(i + RowOffset).EntireRow.Copy
Worksheets("Country").Activate
Excel.Range("A2").Insert Shift:=xlDown
Worksheets("Sheet1").Activate
End If
Next i
Now the code works fine, except for when I enter Japan or USA, Excel freezes. Both have the highest number of entries in my spreadsheet. China has about 4,500 it works fine, USA has 6,500 and japan even more. I am turning screen updating off and formula calculation to manual. I really am not sure why this is occurring, am I trying to push my PC beyond its capabilities, or is there something wrong with the code?
Many thanks to anyone who can offer any advice.
-
Jul 6th, 2006, 03:46 PM
#2
Re: Excel freezes when running code
does it ever come back??
or when it freezes.. is it "done"
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 7th, 2006, 05:52 AM
#3
Re: Excel freezes when running code
if you address each sheet, instead of activating them when you copy, it will probably cut down the time
VB Code:
Country = InputBox("Enter a country name")
NoClients = Application.WorksheetFunction.CountIf(Range("A:A"), "<>") - 1
For i = NoClients To 0 Step -1
If Cells(i + RowOffset, ColumnOffset) = Country Then
Rows(i + RowOffset).EntireRow.Copy
'Worksheets("Country").Activate
sheets("Country").Range("A2").Insert Shift:=xlDown
'Worksheets("Sheet1").Activate
End If
Next i
don't know that will help with your problem though
pete
-
Jul 7th, 2006, 11:59 AM
#4
Re: Excel freezes when running code
...and put a DoEvents in your big loop.
-
Jul 7th, 2006, 12:35 PM
#5
Re: Excel freezes when running code
Also do a ScreenUpdating to help free cpu cycles.
VB Code:
'Turn updating of screen off
Application.ScreenUpdating = False
'Do your loop
'Finish loop
'Turn updating back on
Application.ScreenUpdating = True
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|