+ Reply to Thread
Results 1 to 2 of 2

Automatic Goal Seek and Calculate Active Sheet Code

  1. #1
    Registered User
    Join Date
    06-10-2016
    Location
    Shreveport LA
    MS-Off Ver
    2010
    Posts
    1

    Automatic Goal Seek and Calculate Active Sheet Code

    Hey guys, I am pretty handy with Excel except when it comes to the VBA part of it. I did some programming several years ago and have a basic understanding but that was mostly in Java not VBA.

    Basically I am working on a spreadsheet for work that takes a user input APR from an installment loan contract, does the APR calculation, and compares it to the user input to see if it is correct. I found code online to perform an Automatic Goal Seek on my APR calculations to determine what the correct APR should be and it works great! But there's one problem, I need to be able to make it where the user can have a different tab for each contract examined, this could be around 100 tabs in some extreme cases. When I create more than 3 tabs of my APR calculation it starts to take about 45 seconds to perform the calculations. I have a feeling this is because maybe my code is inefficient. I also have a calculate button on each tab running a calculate sheet macro when it is pressed. My understanding is that it should only by calculating the active sheet but I think it may be recalculating every sheet and this is causing the slow down. I need to have this spreadsheet do the calculations as close to instantly as possible.

    Here is the code for the Automatic Goal Seeks and the calculate macro, any suggestions or answers are greatly appreciated!

    Automatic Goal Seek code:

    Private Sub Worksheet_Calculate()
    Static isWorking As Boolean

    With Sheet1 // The first if statement calculates APR for one scenario and the second calculates APR for a different scenario
    If Round(.Range("P46").Value, 6) <> 0 And Not isWorking Then
    isWorking = True
    .Range("P44").Value = 0
    .Range("P46").GoalSeek Goal:=Range("B13").Value, ChangingCell:=.Range("P44")
    isWorking = False
    End If

    If Round(.Range("P51").Value, 6) <> 0 And Not isWorking Then
    isWorking = True
    .Range("P49").Value = 0
    .Range("P51").GoalSeek Goal:=Range("B13").Value, ChangingCell:=.Range("P49")
    isWorking = False
    End If
    End With
    End Sub

    Calculate Sheet Macro:

    Sub Calculate_Sheet()
    '
    ' Calculate_Sheet Macro
    ActiveSheet.Calculate
    End Sub

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,907

    Re: Automatic Goal Seek and Calculate Active Sheet Code

    This forum can be strict about rules like putting code tags around code. You want to comply so your topic does not get locked.

    It is probably going to be difficult to really help here without seeing a working, dummy copy of your spreadsheet that exhibits the problem. Upload a sample spreadsheet to the forum (Go advanced --> manage attachments -> upload file)

    Do you understand and can you explain the math behind your problem? How is APR defined? Sometimes the easiest way to solve this kind of problem is to resort (heaven forbid) to algebra and solve for APR algebraically, then put that formula into Excel. Or, if this is more of a present value/future value/ internal rate of return type problem (you would have to understand the business math well enough to identify that kind of problem), then you can use the appropriate formula in Excel (list of functions: https://support.office.com/en-us/art...1-da16e8168cbd look through the list of financial functions. The PV functions seem to have the most information on these kind of problems).

    If you were interested, I suspect the strategy I describe here (http://www.excelforum.com/tips-and-t...ind-roots.html ) to write your own root finding algorithm in the spreadsheet would work at least as well if not better for your root finding 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. Automatic Goal Seek That References Cell For Target Value
    By Navigator16171 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-23-2016, 05:52 AM
  2. Automatic goal seek program
    By calltobala in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:14 PM
  3. Excel VBA Multiple Automatic Goal Seek Required – Please Assist us
    By champaben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2014, 04:22 PM
  4. [SOLVED] Automatic Goal Seek
    By Talazem in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-04-2013, 11:28 AM
  5. Faster calculation for multiple automatic goal seek
    By lockd in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-26-2013, 09:30 AM
  6. Automatic Goal Seek VBA won't work now
    By Brodie05 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2013, 08:43 PM
  7. How to calculate a price using goal seek?
    By karo3440 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-25-2011, 03:26 AM

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