Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 30th, 2011, 06:21 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old January 1st, 2012, 12:11 AM
Friend of Wrox
Points: 3,053, Level: 23
Points: 3,053, Level: 23 Points: 3,053, Level: 23 Points: 3,053, Level: 23
Activity: 57%
Activity: 57% Activity: 57% Activity: 57%
 
Join Date: Sep 2005
Location: , , .
Posts: 810
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)
Reply With Quote
  #3 (permalink)  
Old January 1st, 2012, 09:48 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #4 (permalink)  
Old January 1st, 2012, 10:29 PM
Friend of Wrox
Points: 3,053, Level: 23
Points: 3,053, Level: 23 Points: 3,053, Level: 23 Points: 3,053, Level: 23
Activity: 57%
Activity: 57% Activity: 57% Activity: 57%
 
Join Date: Sep 2005
Location: , , .
Posts: 810
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)
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03: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 10:57 AM
Query Optimisation artidatanova SQL Server 2000 1 April 4th, 2005 09:42 PM
Search Engine Optimisation mekh HTML Code Clinic 1 February 25th, 2005 04:54 AM



All times are GMT -4. The time now is 01:27 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.