+ Reply to Thread
Results 1 to 14 of 14

VBA required for Goal Seek solution

  1. #1
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    VBA required for Goal Seek solution

    Seeking expert's help!

    I need a VBA for goal seek to find the advances required in row 5, round to nearest hundreds, so that the bank balances in row 7 will be at least the values in row 9

    Thank you!
    Joseph

    Goal Seek in VBA.png
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,615

    Re: VBA required for Goal Seek solution

    GoalSeek could be used, but why not use just formula in E5 and copied to right:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ?
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,615

    Re: VBA required for Goal Seek solution

    PS. If for some reason you NEED using goalseek, the code could look like this:
    Please Login or Register  to view this content.
    but please make sure that row 5 contains values, not formulas (so the workbook you posted is OK, but if you tested my proposition from the above post, the code will fail).
    if there are chances taht somebody have written a formula in row 5 use the following code
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    Thank you Kaper, it's actually much more complicated than the sample data.

  5. #5
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    The code works perfectly in the sample file.

    Is it possible to make the code flexible to allow for inserting rows and columns, say with named-ranges?

    Thank you.

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,615

    Re: VBA required for Goal Seek solution

    Probably - yes.
    Show representative sample file.

  7. #7
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    Thank you, Kaper. I have now named the range E5:G5 as "Advances" and range E9:G9 as "MinBal".

    Please see attached file.

    Thank you.
    Attached Files Attached Files

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,615

    Re: VBA required for Goal Seek solution

    I've added third named range
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    as we need 3 elements - value to be changed, real balance and required balance, and you have named only 2 of them.

    The adopted code is:
    Please Login or Register  to view this content.
    Press the GoalSeek button (shape) in the attached file, to see how it works.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    Thank you Kaper! Works perfectly! Here's Rep.

  10. #10
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    Dear Kaper

    When the Bank balance c/f > Min. bank balance to maintain, a repayment of advance is made, but should not be more than the Cumulative advances made previously.

    In Period 3 below, the repayment should be capped at 6,600, the Cumulative advances at end of Period 2.

    Please help to take a look.

    Thank you.
    Joseph

    Goal Seek in VBA 2.png
    Attached Files Attached Files
    Last edited by josephteh; 08-30-2021 at 09:08 AM.

  11. #11
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: VBA required for Goal Seek solution

    Please try

    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    Thank you Bo_Ry for the VBA code - it works. But... is it possible to use the range name "BankBalance" instead of using OFFSET to reference the range?

    My actual data has rows in between.

    Thank you.

  13. #13
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: VBA required for Goal Seek solution

    New Range name:
    Cumulative =$E$14:$J$14

    Please Login or Register  to view this content.

    or Formula

    E8
    =MAX(ROUNDUP((E12-SUM(E6:E7)-D9)/(1-$D9),-2),-SUM($D8:D8))
    Attached Files Attached Files
    Last edited by Bo_Ry; 08-30-2021 at 01:50 PM.

  14. #14
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,055

    Re: VBA required for Goal Seek solution

    Thanks Bo_Ry.. works perfectly! Here's Rep for you.

+ 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. Goal Seek with If Then in VBA
    By mvparker79 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2019, 03:56 PM
  2. What is use of Goal Seek
    By Terressa in forum Excel General
    Replies: 1
    Last Post: 07-07-2015, 07:10 AM
  3. [SOLVED] Seeking Goal without using Goal Seek
    By Doc Science in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-07-2015, 02:24 PM
  4. 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
  5. Replies: 3
    Last Post: 07-27-2012, 01:44 PM
  6. Goal Seek VBA with relative 'Goal' parameter
    By alirulez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2012, 07:19 PM
  7. Goal Seek Formula But Not Using Goal Seek
    By cady923 in forum Excel General
    Replies: 1
    Last Post: 08-05-2011, 03:53 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