+ Reply to Thread
Results 1 to 13 of 13

Insert rows automatically based on account number

  1. #1
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Insert rows automatically based on account number

    I'm working in a template which is designed to compute tax credits which is a standardized template. The template is organized by account numbers which are all rows.

    When I populate this template with real data sets, the data set may have account numbers which are not included in the original template. This is usually the case. It's quite easy to identify which account numbers are missing from the template through performing a vlookup.

    However, once I've identified the missing account numbers, I'm struggling to figure out a way to add them into the template without manually adding them. I would also like to ensure they are added in the correct place in the template meaning they are organized in sequential order. All account numbers are formatted as text and are 4 characters long (in both the template and data set). There are many subtotals in the template based on class of account number (first 2 digits in the 4 digit account number) so it isn't as simple as adding the accounts to the end of the template and then sorting sequentially.

    Is there a way to take the account numbers which I've identified need to be added to the template, and use a macro to add rows automatically add them in the template and also ensure it is added in the correct section to ensure the subtotals down-add the new accounts properly?

    In the attached spreadsheet the "Accounts" tab is the standardized template. The "detail" tab is the dataset. The "Account Compare" tab has a column titled "Accounts to be added" which are all the accounts which need to be added into the template in the "Accounts" tab.

    Please let me know if there is an elegant way to do this.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Insert rows automatically based on account number

    Hello and welcome to the forum,

    Here's a suggestion for you. I added comments in the code for your understanding.

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    Thank you so much. I'm actually quite unfamiliar with VBA code and I'm in the process of beginning to learn for work. Is it as simple as copy and pasting this code? Do your comments need to be removed?

  4. #4
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Insert rows automatically based on account number

    Hi,

    Yes, you simply need to copy paste the code. Comments can stay there.

    1. open your file
    2. open the vba editor (ALT + F11)
    3. in the vba editor, you should see your file inthe "Project - VBAProject" Pane. Select (click) it.
    4. add a new module (ALT + I + M)
    5. Copy paste the code in the module.

    To run the macro, you can either add a button in your file and link to the macro
    or launch the macro by doing ALT + F8 and selecting it.

  5. #5
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    Thanks again so much. The comments we're helpful in following the logic too since I'm familiar with the excel functions.

  6. #6
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    Would you happen to have any introductory resources or material which would be a good starting point for learning the code?

  7. #7
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Insert rows automatically based on account number

    Hi,

    I would say Google will be your best friend for this. There are many good websites, blogs and forum where you can learn VBA, starting from the base. It's difficult to recommend you one in particular since all have their own style.
    I also learned a lot by looking at forums such as this one and trying to understand the code posted by others.

  8. #8
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    Okay, thank you for the suggestions.

    I had one more question regarding the original code you provided. Is there a way to modify it to have the newly inserted rows copy formatting/formulas from the row above? My intention would be to not have to manually add the formulas into the blank cells once the new row is created. Instead I would want the new row to appear with the correct formulas (I think you could rely on the formatting of the row above).

    Thanks

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Insert rows automatically based on account number

    There's a thread by Benishiro in tips and tutorials that many have found to be invaluable.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  10. #10
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Insert rows automatically based on account number

    Hello,

    Here's the modified code. It will copy the format and formula from the row above.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    The modified code still didnt seem to copy formulas from above rows. As is this is still quite useful to me.

  12. #12
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    Nevermind, it worked like a charm. Thank you!

  13. #13
    Registered User
    Join Date
    12-12-2018
    Location
    Ottawa, Ontario
    MS-Off Ver
    2016
    Posts
    10

    Re: Insert rows automatically based on account number

    Hi,

    Just revisiting this. There is another modification I require. I tried to think about how to fix it on my own looking at the existing code but I couldn't figure out how as I'm still not that experienced. As prior mentioned, I needed the macro, when it added rows, to also copy & paste the formulas from the row above. There is a formula which is whited out in column A in the "Accounts" tab which I also want copied with every row added. The current macro seems to only copy formulas from column B onwards. Is it possible to modify the code so that it copies all formulas from the row above (column A included)? I've attached workbook for your reference.
    Attached Files Attached Files
    Last edited by 11ak117; 01-21-2019 at 04:34 PM.

+ 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: 4
    Last Post: 12-10-2014, 08:47 PM
  2. IF Statement that will assign account types based on "account number"
    By aladdin16 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-08-2014, 05:04 PM
  3. [SOLVED] insert rows based on number in cell and copy the data down into the new rows
    By pziefle in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-05-2013, 11:19 AM
  4. [SOLVED] How to censor account numbers based on how many characters are in the account number
    By Mcorydon in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-25-2013, 01:06 PM
  5. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  6. Summing Rows based on Account Number
    By chalaki in forum Excel General
    Replies: 1
    Last Post: 06-21-2011, 02:12 PM
  7. [SOLVED] Automatically insert rows based on lookup of data
    By linksavage in forum Excel General
    Replies: 0
    Last Post: 12-21-2010, 09:05 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