+ Reply to Thread
Results 1 to 3 of 3

Optimizing goal and seek code.

  1. #1
    Registered User
    Join Date
    10-31-2014
    Location
    Latvia
    MS-Off Ver
    2015
    Posts
    1

    Optimizing goal and seek code.

    Hey!

    I'd really appriciate if someone could suggest how to optimize this code. As you can see it is repeating itself over and over and therefore runs slowley.
    I'm a beginner at this so help me out if you can.
    Any suggestions?

    Please Login or Register  to view this content.
    Last edited by saknem08; 11-05-2014 at 02:37 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,264

    Re: Optimizing goal and seek code.

    Instead of "here's my code" a better way is "here's what I want to do" along with "here's what's in S68, S10, and L68."
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,369

    Re: Optimizing goal and seek code.

    This forum can be pretty strict about putting code inside of code tags. If you need instructions, check out the FAQ and Forum Rules links, and edit your post to conform to the rule (this could be an interesting discussion, and I would hate to have it shut down for such a little thing).

    Be sure to include some of the little things (like turning screen updating off).

    In part, this is difficult to give a complete answer without understanding the math behind the S68 calculation and how i fits into that calculation. If you explored the math around the problem, you might find a completely different solution than the kind of solution you are proposing here.

    One thing I notice is that you are using some kind of "brute force" algorithm, counting i from 1 to 1000 and capturing different results. You indicate that you are a beginner, does this mean you are a beginner only to VBA, or are you also a beginner to numerical methods/algorithms as well? If you understand the math behind what you are doing, you should be able to come up with a different "root finding algorithm" (bisection or method of false position come immediately to my mind based on what you have posted) that will allow you to find each solution in <100 iteration rather than the 1000 iterations you are currently using. (Wikipedia description of different root finding algorithms: http://en.wikipedia.org/wiki/Root-finding_algorithm ).

    If you are unfamiliar with the actual behavior of the function(s) being solved here, you might consider spending some more time becoming more familiar with the behavior of the function(s). An improved solution may become obvious as you become more familiar with the problem.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Code to run a goal seek
    By michaeldouglas in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-10-2014, 02:16 PM
  2. Argument not optional error is occurring in goal seek automated code.
    By bk1202 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-21-2013, 08:32 AM
  3. Multiple Goal Seek VBA Code
    By excelwannabeee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2012, 01:30 PM
  4. Help with code for Goal Seek
    By LSB M in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2012, 07:33 PM
  5. Determining VBA Code for Goal Seek
    By BFlick11 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-12-2011, 01:28 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