+ Reply to Thread
Results 1 to 3 of 3

Adjust a cell value to get a constant value for another cell

  1. #1
    Registered User
    Join Date
    07-14-2014
    Location
    Norway
    MS-Off Ver
    2007
    Posts
    10

    Adjust a cell value to get a constant value for another cell

    Hello. I am a beginner in programming in vba excel and at the moment struggling with the following problem:
    I have cell C5 value set as 5*B5+3. Now, using vba,I would like to adjust the value of B5 (basically find it), so that the value of C5 is let's say 8.
    In this easy example, one can find rapidly the correct value of B5 to be 1.

    What I've tried is the following code:

    Private Sub CommandButton1_Click()

    Range("B5").Value = -5
    Do
    Range("B5").Value = Range("B5").Value + 1
    Loop Until Range("C5").Value = 8
    End Sub

    So, I am setting the initial guess for cell B5 and then increasing it by 1.
    However, if I set the increment to 0.5 instead of 1, program goes crazy and loop doesn't close.
    Could you please suggest what changes should I introduce to this code, so that even if the increment is 0.001 everything will work or maybe anyone could suggest a better approach to the problem?
    Thank you in advance.
    Last edited by sergiupa; 07-30-2014 at 06:29 PM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166
    Hello sergiupa,

    Welcome to Excelforum. Be a part of large Excel community. Enjoy Learning.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,877

    Re: Adjust a cell value to get a constant value for another cell

    This is the Introduction Forum where no questions should be posted. If you start a thread in any of the other sub-forums, I´m sure it will not take long before your request will be solved there.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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. Replies: 1
    Last Post: 09-18-2013, 01:58 PM
  2. Automatically Adjust Cell Height Based On Other Cell Value
    By Muttly in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-24-2013, 06:36 AM
  3. IF function help with one constant cell and one variable cell
    By hwatson86 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-30-2012, 03:17 AM
  4. [SOLVED] Adjust Multiple Cell Borders Based on Cell Contents
    By USFishin in forum Excel General
    Replies: 16
    Last Post: 04-10-2012, 12:56 AM
  5. How do you convert a formula cell to a constant cell
    By JQLogan in forum Excel General
    Replies: 1
    Last Post: 03-29-2005, 04:06 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