Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2011, 06:21 PM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Code Optimisation

Hi

I need to get this VBA to speed through n rows as quickly as possible, doing 20 rows is fine, 5000 rows takes about 18minutes, before adding the:

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
&
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

it took 6.5hours to run through 43000 rows. I have automatic calculation set to manual at present as well.

Code currently in use as below:

-----------

Sub Calc()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim lRowLoop As Long, lLastRow As Long
lLastRow = ActiveSheet.Cells(Rows.Count, "Q").End(xlUp).Row
For lRowLoop = 2 To lLastRow
ActiveCell.GoalSeek Goal:=1, ChangingCell:=ActiveCell.Offset(0, -1)
ActiveCell.Offset(1, 0).Select
Next lRowLoop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Please help
 
Old January 1st, 2012, 12:11 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You can try

Code:
For lRowLoop = 2 To lLastRow
Cells(lRowLoop, 2).GoalSeek Goal:=1, ChangingCell:=Cells(lRowLoop, 1)
Next lRowLoop
Can speedup a bit as no selection is involved

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old January 1st, 2012, 09:48 AM
Registered User
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Shasur,

Thanks for the reply, I edited the code to read:

Sub Rhys()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim lRowLoop As Long, lLastRow As Long
lLastRow = ActiveSheet.Cells(Rows.Count, "Q").End(xlUp).Row
For lRowLoop = 2 To lLastRow
Cells(lRowLoop, 2).GoalSeek Goal:=1, ChangingCell:=Cells(lRowLoop, 1)
Next lRowLoop
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

But now I'm getting a 1004 runtime error on it, any ideas?
 
Old January 1st, 2012, 10:29 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you try with

Code:
Cells(lRowLoop, 17).GoalSeek Goal:=1, ChangingCell:=Cells(lRowLoop, 16)
It might be due to the wrong column numbers ..

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Application Optimisation R4VEN ASP.NET 4 General Discussion 9 December 9th, 2010 07:51 AM
Search Engine Optimisation SouthendSupporter ASP.NET 3.5 Basics 1 August 6th, 2009 02:59 PM
Optimisation TIP: Viewstate jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 May 15th, 2007 09:57 AM
Query Optimisation artidatanova SQL Server 2000 1 April 4th, 2005 08:42 PM
Search Engine Optimisation mekh HTML Code Clinic 1 February 25th, 2005 04:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.