+ Reply to Thread
Results 1 to 15 of 15

Automatically update cell using VB code

  1. #1
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Automatically update cell using VB code

    Hi everyone,

    I cant seem to figure out how to calculate automatically in a sheet. For example, in cell A1 the value is 9 and in cell B1 value is 9. using vb code i want formula in cell C1 (=b1/c1). Now everytime i change the value in A1 or B1 the value in C1 automatiaclly changes.

    Thanks

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Automatically update cell using VB code

    Quote Originally Posted by biznez View Post
    Hi everyone,

    I cant seem to figure out how to calculate automatically in a sheet. For example, in cell A1 the value is 9 and in cell B1 value is 9. using vb code i want formula in cell C1 (=b1/c1). Now everytime i change the value in A1 or B1 the value in C1 automatiaclly changes.

    Thanks
    Are you saying that it automatically changes, and you don't want it to?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Automatically update cell using VB code

    Quote Originally Posted by Arkadi View Post
    Are you saying that it automatically changes, and you don't want it to?
    i want it to automatically change

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Automatically update cell using VB code

    This code:
    Please Login or Register  to view this content.
    would put a formula in C1 that changes whenever a1 or b1 is changed

  5. #5
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Automatically update cell using VB code

    Quote Originally Posted by Arkadi View Post
    This code:
    Please Login or Register  to view this content.
    would put a formula in C1 that changes whenever a1 or b1 is changed
    do i put this in a module or the sheet?

  6. #6
    Valued Forum Contributor Saarang84's Avatar
    Join Date
    02-19-2009
    Location
    Chennai, India
    MS-Off Ver
    XL 2003 to 2010
    Posts
    812

    Re: Automatically update cell using VB code

    Put this in a module and assign that Sub to a button.
    To insert a button go to Developer tab > Design Mode > Insert Form Controls > Button
    If my assistance has helped, there is a reputation icon * on the left hand corner below the post - you can show your appreciation to the user who has helped in resolving your requirement.

    If your requirement has been solved please mark your thread as Solved.
    In the menu bar above the very first post, select Thread Tools, then select "Mark this thread as Solved".

    Kindly use [FORMULA] or [CODE] tags when posting your code.

    Regards,
    Sarang

  7. #7
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Automatically update cell using VB code

    Quote Originally Posted by Saarang84 View Post
    Put this in a module and assign that Sub to a button.
    To insert a button go to Developer tab > Design Mode > Insert Form Controls > Button
    thats what im trying to avoid. i dont want to execute the macro everytime. I just want it to do it automatically when number is changed.
    is this possible?

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Automatically update cell using VB code

    ????? by putting a formula in, the update will always happen.... why do you need a macro for this? If you really need one then forget the formula and do a sheet_change event...

    Is it only the one cell that needs updating? and is it actually the cells you described?

  9. #9
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Automatically update cell using VB code

    Quote Originally Posted by Arkadi View Post
    ????? by putting a formula in, the update will always happen.... why do you need a macro for this? If you really need one then forget the formula and do a sheet_change event...

    Is it only the one cell that needs updating? and is it actually the cells you described?
    Sorry Arkadi, but what do you mean sheet_change event?

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Automatically update cell using VB code

    Look, once a forumla is in the cell, it will always calculate when the other cell changes... is that not enough? if you want code to run every time, we can work on that.

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Automatically update cell using VB code

    A worksheet change event is a macro that runs whenever the contents of the sheet change.

  12. #12
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Automatically update cell using VB code

    yea that would be something i want

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Automatically update cell using VB code

    You asked earlier where to put the code... let me ask this... can't you just put the formula in the cell and save the file? then it stays there...

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Automatically update cell using VB code

    Hello biznez,

    For example, in cell A1 the value is 9 and in cell B1 value is 9. using vb code i want formula in cell C1 (=b1/c1). Now everytime i change the value in A1 or B1 the value in C1 automatiaclly changes.
    Is that a typo maybe, because if you would want to do that, you would get a circular error.

    Why do you need VBA for this?

    Could it be that there may be more behind than, what you state in your requirement?

    To help us taking guessing out of your issue, please attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  15. #15
    Forum Contributor
    Join Date
    12-11-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    517

    Re: Automatically update cell using VB code

    Quote Originally Posted by Arkadi View Post
    You asked earlier where to put the code... let me ask this... can't you just put the formula in the cell and save the file? then it stays there...
    yea i think you are right Arkadi. This will be quicker, i just protected the sheet so no one can delete the formulas
    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. Automatically update only with numbers(ifnumber-update and go to next cell)
    By moldo89 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-18-2013, 11:10 AM
  2. Automatically update only with numbers(ifnumber-update and go to next cell)
    By moldo89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2013, 03:06 AM
  3. Replies: 4
    Last Post: 10-18-2013, 02:52 AM
  4. [SOLVED] Automatically copy and paste (or update) cell values to another worksheet using VBA code
    By jjin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-21-2013, 04:56 AM
  5. update VBA code automatically when worksheet changes
    By winamd72 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2008, 06:37 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