+ Reply to Thread
Results 1 to 10 of 10

vba code to insert blank line after two criteria and copy down criteria

  1. #1
    Registered User
    Join Date
    02-02-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    6

    vba code to insert blank line after two criteria and copy down criteria

    Hello Forum

    This is my first time using it. I'm very inexperienced when it comes to using vba. I'm hoping someone can assist me in writing macro vba code to accomplish the following. I have 4 columns: A (Account Code) B (Dr) C (Cr) D (Description) - as indicated below

    Account Code Dr Cr Description
    13410 10 0 Narration 1
    13420 20 0 Narration 2
    13430 30 0 Narration 3
    13440 40 0 Narration 4

    Every time the macro sees the account code of 13410 in column A a blank row needs to be inserted below and a corresponding credit amount in column C needs to be entered with say an account code of 98450 with the same narration.

    Again every time the macro sees the account code of 13430 a blank row needs to be inserted and a corresponding credit line in column C needs to be entered with say an account of 97730 with the same narration.

    Looking like this:

    Account Code Dr Cr Description
    13410 10 0 Narration 1
    98450 0 10 Narration 1
    13420 20 0 Narration 2
    13430 30 0 Narration 3
    97730 0 30 Narration 3
    13440 40 0 Narration 4

    I will be very much appreciated. I haven't found any forums with two criteria and hence hopeful someone can please assit.
    Thanks heaps!!

    James

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code to insert blank line after two criteria and copy down criteria

    Give this a whirl:

    Please Login or Register  to view this content.
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Registered User
    Join Date
    02-02-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: vba code to insert blank line after two criteria and copy down criteria

    Hey thank you for your swift response! I'm very grateful. I've tried using the code inserting it into a module. The example using account code 13430 resulted in the correct blank line being inserted with the credit account code 97730, however the example using account code 13410 did not produce the blank row and associated account code of 98450.

    I noticed in the vba code (iCredit) that the amounts of $10, $20, $30 and $40 were hard coded into the macro. Can this be changed so that whatever $ amount is in column B will replicate in the credit column being column C.

    I've tried to upload a spreadsheet but I'm not yet up on doing so.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code to insert blank line after two criteria and copy down criteria

    I tested the code on a test workbook and it worked perfectly fine for me. In response to;
    Can this be changed so that whatever $ amount is in column B will replicate in the credit column being column C.
    This contradicts with your original post and is not clear as to what you really want. Submit an example workbook with a clear before and after example if you would like an amended response.

  5. #5
    Registered User
    Join Date
    02-02-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: vba code to insert blank line after two criteria and copy down criteria

    Hello & Good morning!

    Thank you again for giving you're time ...It's very much appreciated!!.

    I'm attempting to upload a spreadsheet to simulate the before and after result.
    When I've run the macro only the rows with account code # 13430 has inserted a row below with the correct vba code of 97730. This did not
    take place for account code 13410 which I'd also like to have a row inserted below with the account code of 98450.

    The values in column B will vary, so I'm hoping that whatever value is say in cell B13 will then also replicate to cell C14. Perhaps by way of the
    Offset function. The narration in row13 needs to be the same for row14 when the row is inserted.

    On a separate issue when trying to run the vba code on another report that has all the detailed information a Run-time Error 13 appears.
    I've attached this snipping tool picture as well indicating the issue.

    I'm using Excel 2007 however I've tested the macro on Excel 2010 and the same issues have arisen.

    Thank you so much for your time again. I hope I've been able to elaborate on my query.

    Kind regards
    James
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code to insert blank line after two criteria and copy down criteria

    Here is the amended code:

    Please Login or Register  to view this content.
    On a separate issue when trying to run the vba code on another report that has all the detailed information a Run-time Error 13 appears.
    What you have identified is not actually causing the error. I would have to see the file you referenced to identify the true issue.

  7. #7
    Registered User
    Join Date
    02-02-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: vba code to insert blank line after two criteria and copy down criteria

    Hi Again

    I've upload a spreadsheet book2.xlsm which has the amended code. Unfortunately it's moved the amount destined for column C to column D. Thank you still for your efforts.

    Very much appreciated.
    James
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-02-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: vba code to insert blank line after two criteria and copy down criteria

    My apologies

    I've just realized the the updated book2.xlsm spreadsheet in my previous post wasn't set up with columns A B C D. The code is working all apart from the fact that account code 13410 in column A isn't having a line inserted below with the account code 98450 and the corresponding amount in column C of $1 and Naration 1 in column D. Else it's working great!

    Perhaps it's someone unique on my end that's causing it not to function. book3.xlsm is attached.

    Thanks a million for all your time & efforts ... really appreciated!!
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: vba code to insert blank line after two criteria and copy down criteria

    It is because your previous attached Book1 didn't start at row 1. I assumed a header so didn't have it look at row 1. Just another reason why it is always a good idea to submit an example workbook that matches your real workbook as close as possible.

    Change this line:

    Please Login or Register  to view this content.
    to this

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-02-2013
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: vba code to insert blank line after two criteria and copy down criteria

    Thank you very much. Your assistance has been much appreciated. And yes good advice to upload a spreadsheet.

+ 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. Copy rows and insert data if criteria is met ?
    By wuf_1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-05-2014, 05:37 AM
  2. [SOLVED] insert a blank row and calculate the auto sum with month criteria
    By pani_hcu in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-10-2014, 03:58 PM
  3. VB Code to insert row with certain criteria
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2014, 09:52 AM
  4. [SOLVED] Copy only When criteria met. Skip to next line if Criteria not met.
    By excellearner121 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 03-10-2014, 09:16 AM
  5. [SOLVED] VB code help- need copy cells in a row and paste to new sheet on next available blank line
    By Barbara Excel in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-27-2012, 03:11 PM
  6. [SOLVED] How to insert blank row below when find my criteria?
    By krasi_e_d in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2012, 10:26 AM
  7. Replies: 5
    Last Post: 09-07-2011, 11:14 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