+ Reply to Thread
Results 1 to 14 of 14

Macro to Automatically Calculate a New Row?

  1. #1
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Macro to Automatically Calculate a New Row?

    I have this formula for one of my columns =COUNTIFS($B$2:$B2,$B2,$A$2:$A2,">="&C2)

    How can I create a VBA/macro so that when I enter a new row of data, it will automatically calculate the cell in this column? I don't want to have to keep dragging down the formula... Thanks

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Macro to Automatically Calculate a New Row?

    You can probably just do it with formula. Take a look at this post.
    http://www.ozgrid.com/forum/showthread.php?t=150363

  3. #3
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Re: Macro to Automatically Calculate a New Row?

    Quote Originally Posted by JieJenn View Post
    You can probably just do it with formula. Take a look at this post.
    http://www.ozgrid.com/forum/showthread.php?t=150363
    I need the macro prompt...and probably some step by step instructions. I'm new to VBA/macros :-/

  4. #4
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Macro to Automatically Calculate a New Row?

    Right click on the target sheet and click on "View Code".
    The code will go in this window and not any standard module.

    Paste this code in the window-
    Please Login or Register  to view this content.
    Happy to Help

    How to upload excel workbooks at this forum - http://www.excelforum.com/the-water-...his-forum.html

    "I don't get things easily, so please be precise and elaborate"

    If someone's post has helped you, thank by clicking on "Add Reputation" below the post.
    If your query is resolved please mark the thread as "Solved" from the "Thread Tools" above.

    Sourabh

  5. #5
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Re: Macro to Automatically Calculate a New Row?

    Quote Originally Posted by sourabhg98 View Post
    Right click on the target sheet and click on "View Code".
    The code will go in this window and not any standard module.

    Paste this code in the window-
    Please Login or Register  to view this content.
    I just tried this but nothing happened. It kept the cell in column D blank when I went to add a new row of data. Tells me that there is no macro name either when I go to run it.
    Last edited by raeinla; 11-18-2016 at 03:26 PM.

  6. #6
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Macro to Automatically Calculate a New Row?

    excelforum004.xlsm

    Whenever any changes occur in column A, B or C, column D is auto-Calculated. It works well for me.

  7. #7
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Re: Macro to Automatically Calculate a New Row?

    Quote Originally Posted by sourabhg98 View Post
    Attachment 489951

    Whenever any changes occur in column A, B or C, column D is auto-Calculated. It works well for me.
    So I got this to work, but it will only add a row above my last row of data, not after like I want. If I run the macro and click in the D column cell in the row in which I want to add data, nothing happens.. what am I doing wrong?


    Sub AddRowCopyFormulaInColumnI()
    ActiveCell.EntireRow.Insert
    Cells(ActiveCell.Row + 1, "D").Copy Cells(ActiveCell.Row, "D")
    End Sub

  8. #8
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Macro to Automatically Calculate a New Row?

    I am not sure what you exactly mean by "above" and "after", could you tell step by step what will you do and what you want to happen?

  9. #9
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Re: Macro to Automatically Calculate a New Row?

    I have 19 rows of data. For Cell D2, my formula is =COUNTIFS($B$2:$B2,$B2,$A$2:$A2,">="&C2). For Cell D20, my formula is =COUNTIFS($B$2:$B20,$B20,$A$2:$A20,">="&C20)... so every new D column cell formula adjusts accordingly. I want to create a macro that when I enter a word into B21, cell D21 will automatically be calculated (so I don't have to drag down the formula every single time). I hope this better clarifies what I'm trying to do.

  10. #10
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Macro to Automatically Calculate a New Row?

    So in the file I attached, we have 4 rows of data, and when we enter anything in Cell A6, B6 or C6 the new result gets calculated in cell D6.

    Isn't it what you are trying to achieve?

  11. #11
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Re: Macro to Automatically Calculate a New Row?

    Quote Originally Posted by sourabhg98 View Post
    So in the file I attached, we have 4 rows of data, and when we enter anything in Cell A6, B6 or C6 the new result gets calculated in cell D6.

    Isn't it what you are trying to achieve?
    This is the data I'm working with (see attached). I'm wanted D to be automatically calculated everytime I enter a new product code row.
    Attached Files Attached Files

  12. #12
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899
    Quote Originally Posted by raeinla View Post
    This is the data I'm working with (see attached). I'm wanted D to be automatically calculated everytime I enter a new product code row.
    Copy paste this data in my sheet and try adding new data in the next row. The result will be auto-calculated.

  13. #13
    Registered User
    Join Date
    11-13-2016
    Location
    Los Angeles
    MS-Off Ver
    Windows 7
    Posts
    10

    Re: Macro to Automatically Calculate a New Row?

    Quote Originally Posted by sourabhg98 View Post
    Copy paste this data in my sheet and try adding new data in the next row. The result will be auto-calculated.
    I got that to work. One last question... and then thank you so much. Say I add two more columns of data. How can I run my macro so that it calculates BOTH D and F at the same time?
    Attached Files Attached Files

  14. #14
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899
    Quote Originally Posted by raeinla View Post
    I got that to work. One last question... and then thank you so much. Say I add two more columns of data. How can I run my macro so that it calculates BOTH D and F at the same time?
    Please Login or Register  to view this content.

+ 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 calculate formula automatically from a list of input and save each result
    By Alex Zana in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2016, 07:07 AM
  2. Do not automatically calculate when file name contains
    By iecbso in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2015, 07:54 AM
  3. [SOLVED] How to calculate formulas automatically
    By pgft in forum Excel Formulas & Functions
    Replies: 31
    Last Post: 05-20-2013, 06:16 AM
  4. Calculate automatically
    By colors632 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2010, 03:09 AM
  5. calculate date automatically.
    By Seroleh in forum Excel General
    Replies: 4
    Last Post: 05-28-2009, 11:45 PM
  6. Automatically calculate VBA code
    By n1k in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2008, 12:09 PM
  7. automatically calculate price
    By MCD in forum Excel General
    Replies: 2
    Last Post: 12-14-2007, 03:51 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