Results 1 to 8 of 8

How can I make VBA process more efficient?

Threaded View

pholt33 How can I make VBA process... 02-04-2015, 02:57 PM
Brendan_Floyde Re: How can I make VBA... 02-04-2015, 05:48 PM
pholt33 Re: How can I make VBA... 02-05-2015, 10:50 AM
Alf Re: How can I make VBA... 02-05-2015, 06:42 AM
mikerickson Re: How can I make VBA... 02-05-2015, 11:08 AM
pholt33 Re: How can I make VBA... 02-05-2015, 11:12 AM
MrShorty Re: How can I make VBA... 02-05-2015, 11:25 AM
pholt33 Re: How can I make VBA... 02-05-2015, 01:55 PM
  1. #1
    Registered User
    Join Date
    02-04-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    4

    Question How can I make VBA process more efficient?

    I have a bunch of data where I need to make adjustments to certain values using Solver. Doing this manually would take me weeks or more so I set up some looping code to run Solver within VBA. The problem is that it is verrrryy slow.

    Here is my original code:

    Sub Solver()
    '
    Application.ScreenUpdating = False
    
    Dim i As Integer
    
    For i = 660 To 900 'Range("A" & Rows.Count).End(xlUp).Row
    
    If Cells(i, "P") <> "0" And Year(Cells(i, "B")) < "2006" Then
    
        SolverReset
    
        SolverOk SetCell:=Cells(i, "P").Address, MaxMinVal:=3, ValueOf:=0, ByChange:=Cells(i, "Q").Address, Engine:=1 _
            , EngineDesc:="GRG Nonlinear"
        SolverOptions MaxTime:=0, Iterations:=0, Precision:=0.001, Convergence:= _
            0.001, StepThru:=False, Scaling:=False, AssumeNonNeg:=False, Derivatives:=2
    
        SolverSolve userfinish:=True
        
    End If
    
    Next
    
    Application.ScreenUpdating = True
    
    End Sub

    I was thinking that by reordering the steps, I could get the process to run much more efficiently by quickly passing over rows where no action is needed. The code below is what I came up with but it is just as slow as the original.

    Sub Solver2()
    '
    Dim i As Integer
    
    For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
    
    If Cells(i, "P") = "0" Or Year(Cells(i, "B")) > "2005" Then
        'Do nothing
     
        ElseIf Cells(i, "P") <> "0" And Year(Cells(i, "B")) < "2006" Then
    
            SolverReset
    
            SolverOk SetCell:=Cells(i, "P").Address, MaxMinVal:=3, ValueOf:=0, ByChange:=Cells(i, "Q").Address, Engine:=1 _
                , EngineDesc:="GRG Nonlinear"
            SolverOptions Precision:=0.001, Convergence:=0.001, AssumeNonNeg:=False
    
            SolverSolve userfinish:=True
        
    End If
    
    Next
    
    Application.ScreenUpdating = True
    
    End Sub


    How can I make this process run more quickly? Thanks!
    Last edited by pholt33; 02-05-2015 at 01:55 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Most efficient way to script to automate a long process?
    By Arcaklar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-21-2013, 11:55 PM
  2. [SOLVED] How can I make this code more efficient?
    By Mr.Whiskers in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-09-2012, 11:11 PM
  3. How to make Excel VBA more efficient?
    By mhni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2009, 04:31 PM
  4. Make code more efficient
    By allanr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-29-2008, 08:43 PM
  5. need to make code more efficient (if possible)
    By Lilivati in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-07-2006, 02:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1