+ Reply to Thread
Results 1 to 12 of 12

VBA insert a row issue with formula

  1. #1
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    VBA insert a row issue with formula

    Hi All,

    I have a weird issue. I have a VBA that insert row's in my sheet. I also have a formula that does the total of a column but the issue I have is if I select the last row and press the button that trigger the "add row's" then my formula that does the subtotal won't work but if I select any other row and press the button that trigger the "add row's" then the formula update properly.

    EX: my formula is: =SUBTOTAL(109,L6:L25)

    If I select the last row and press the option to add row the formula stay the same thus it's not including the last line in my total.

    but if I select any other row and press the option to add 1 row, my formula will look like this "=SUBTOTAL(109,L6:L26)" and the total is ok since it's calculating the line I added.

    Here's my VBA code:

    Please Login or Register  to view this content.

    Thanks all,

    Marc
    Last edited by r0ot5; 09-09-2013 at 08:09 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA insert a row issue with formula

    If you select the last row of the data range, your code will select the next blank row using this:
    Selection.Resize(rowsize:=2).Rows(2).EntireRow. _
    Resize(rowsize:=vRows)

    and then insert a row before, therefore your subtotal formula should not change to reflect the increased rows. There are a few ways you can fix this, maybe just change your subtotal formula to =SUBTOTAL(109,L6:L26) so that if you an insert a row before L26 it will change to =SUBTOTAL(109,L6:L27)?

  3. #3
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA insert a row issue with formula

    The issue I have is my formula is at the bottom and just after I have another line were I have to input data.

    see screenshot:

    row.jpg

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA insert a row issue with formula

    You could change the formula in the macro?
    something along the lines of:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA insert a row issue with formula

    Not sure how I would do that, I've attache my document for example.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA insert a row issue with formula

    Your vba project is password protected so hard for me to do much but I'd guess you could use:
    Range("L" & usedrange.rows.count).formula = "=SUBTOTAL(109,L6:L" & Range("L" & usedrange.rows.count).row - 1 & ")"
    It needs to be after the code to add the row.

  7. #7
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA insert a row issue with formula

    Sorry about that, I forgot to remove it.

    password for VBA is: routesheet
    password for sheet: pass

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA insert a row issue with formula

    Did you try the code in post #6?

  9. #9
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA insert a row issue with formula

    Yes I did try and it came back has a error, not sure why...

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA insert a row issue with formula

    Try this:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA insert a row issue with formula

    It's doing the same thing, when selecting the last row to insert a line the formula doesn't update but any other row is ok.

  12. #12
    Registered User
    Join Date
    01-16-2013
    Location
    Gatineau, QC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: VBA insert a row issue with formula

    I forgot to mention that I have more then 1 formula on the line.

+ 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. [SOLVED] Insert shift down issue macro issue
    By CC64 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-15-2012, 10:57 PM
  2. [SOLVED] Insert blank row and issue a sum
    By LanceB in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 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