+ Reply to Thread
Results 1 to 10 of 10

Calculating Average once blank row is added

  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Calculating Average once blank row is added

    Hi, after I add in the 2 lines once it finds differences in Column D, I want to average the cell values in Column G and H.

    So it adds 2 blank lines once it finds a difference, then on the first added blank line, I want the average to be calculated automatically for Columns G and H. Where can i add it to the code below?

    Code below:

    Sub InsertLine()
    Dim lRow As Long
    For lRow = Cells(Cells.Rows.Count, "D").End(xlUp).Row To 2 Step -1
    If Cells(lRow, "D") <> Cells(lRow - 1, "D") Then Rows(lRow).EntireRow.Insert
    Next lRow
    End Sub

    Thanks!

  2. #2
    Forum Contributor LokeshKumar's Avatar
    Join Date
    03-31-2015
    Location
    India
    MS-Off Ver
    All, mostly 2010 now..
    Posts
    471

    Re: Calculating Average once blank row is added

    Can you upload the workbook....there would be more simpler code available....
    Lokesh Kumar
    Stay Hungry.. Stay Foolish..
    _________________________________________________________
    Please Click STAR to Add Reputation if my/someone's answer helped!

  3. #3
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Calculating Average once blank row is added

    Quote Originally Posted by LokeshKumar View Post
    Can you upload the workbook....there would be more simpler code available....
    Yup, see attached. Thanks
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Calculating Average once blank row is added

    Hi Branbran10,

    The following Macro may help you. The addition of blank lines or the deletion of blank lines should not affect the Excel Average formula:
    Please Login or Register  to view this content.
    Lewis

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

    Re: Calculating Average once blank row is added

    You can also try this shorter version--
    Please Login or Register  to view this content.
    Just call this macro after inserting rows like this--
    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

  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: Calculating Average once blank row is added

    Sample file attached...
    Press the "Run" Button to get results...
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Calculating Average once blank row is added

    This creates two empty rows to be added to the top.. how can that be fixed?

  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: Calculating Average once blank row is added

    At the end of insert line macro (after "call average") just put-
    Rows("2:3").EntireRow.Delete Shift:=xlUp

  9. #9
    Registered User
    Join Date
    05-14-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    92

    Re: Calculating Average once blank row is added

    Beautiful, thank you!

  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: Calculating Average once blank row is added

    You are most welcome!!
    Thanks for the feedback and reputation!!
    It would be good if you could mark the thread as solved from the thread tolls above...
    Regards
    Sourabh

+ 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: 2
    Last Post: 02-09-2014, 12:40 AM
  2. Replies: 10
    Last Post: 04-25-2013, 06:12 PM
  3. Replies: 5
    Last Post: 06-19-2012, 04:37 PM
  4. Calculating totals from user added worksheets
    By drgogo in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-12-2010, 07:50 AM
  5. calculating average with blank cells
    By marvinks in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-07-2006, 11:34 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