+ Reply to Thread
Results 1 to 3 of 3

Macro to increase cell x value until cell y = cell z

  1. #1
    Registered User
    Join Date
    10-24-2017
    Location
    Portsmouth, England
    MS-Off Ver
    2013
    Posts
    16

    Macro to increase cell x value until cell y = cell z

    Hiya,

    So I'm trying to use a spreadsheet to do reverse tax calculations and am trying to use a macro to achieve this by having it increase the gross salary (Cell F9) until the net salary (Cell B15) equals the desired number (Cell E3).

    I have taken a stab at writing the code however, I'm quite novas when it comes to VBA so it hasn't worked very well. The code I have tried is:

    Please Login or Register  to view this content.
    However it doesn't stop increasing when it meeting the criteria.

    I will be super grateful for any help anyone can give me!

    I have attached my workbook for context.
    Attached Files Attached Files

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

    Re: Macro to increase cell x value until cell y = cell z

    Are you required to use VBA? I think the built in Solver or Goal Seek utilities will do this without needing to write your own routine. Call Solver or goal seek and tell it to set target cello B15 to a value of 30000 by changing F9. If you want to use the target value in E3, enter a helper cell in B16 =B15-E3, then tell it to set B16 to a value of 0 by changing F9.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,164

    Re: Macro to increase cell x value until cell y = cell z

    Hi,

    In your code above, you have two loops. The first is a For..Next loop that goes from 1 to a million and the second (after the first is done) is the Do Until loop (which does nothing inside the loop).

    Cells(row,column) seems to be a problem for you also. Example the cell of B10 is "Cells(10,"B")" or "Cells(10,2)" in VBA.

    I have no idea why you are out 42 columns or down 42 rows for your code. Normally you replace a cell with a formula in it and then do a refresh or calculate and see if x = y to see if you need to jump out of your loop.

    I hope this helps.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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. Macro to increase length of the cell.
    By Prabakaran3003 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2017, 07:49 AM
  2. Replies: 1
    Last Post: 04-02-2017, 10:18 AM
  3. [SOLVED] incremental increase in a cell based on value increase in another cell
    By umuni in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-18-2014, 05:23 AM
  4. Replies: 3
    Last Post: 12-16-2012, 12:49 PM
  5. Replies: 0
    Last Post: 01-10-2012, 03:48 PM
  6. Macro to increase cell value by 1
    By prontrad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2009, 01:08 PM
  7. Using a macro to increase a value in a cell
    By powerman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-26-2005, 09:36 AM

Tags for this Thread

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