+ Reply to Thread
Results 1 to 16 of 16

Insert blank rows based on a cell value

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Insert blank rows based on a cell value

    Hey guys,

    i was wondering if i could ask for some help,

    i am in the process of building a motorbike parts website and i have comprised a list of all bikes of all makes all models and all years, it has over 20,000 rows of data so would be a bit tedious to do manually haha

    here is a sample of the data:

    Honda CRF 150 R----- 7----- KE03A------ JH2KE03A-7K000001------ JH2KE03A-7K099999------ 2007----------- 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 R----- 8----- KE03A------ JH2KE03A-8K100001------ JH2KE03A-8K199999------ 2008----------- 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 R----- 9----- KE03A------ JH2KE03A-9K200001------ JH2KE03A-9K299999------ 2009-2011------ 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 R----- C----- KE03A------ JH2KE03A-CK300001------ JH2KE03A-DK499999------ 2012----------- 1------ 24 BHP, 18 kw------
    Honda CRF 150 R----- D----- KE03A------ JH2KE03A-DK400001------ JH2KE03A-DK499999------ 2013----------- 1------ 24 BHP, 18 kw------
    Honda CRF 150 R----- E----- KE03A------ JH2KE03A-EK500001------ JH2KE03A-DK499999------ 2014-2015------ 1------ 24 BHP, 18 kw------
    Honda CRF 150 RB----- 7----- KE03B------ JH2KE03B-7K000001------ JH2KE03B-7K099999------ 2007----------- 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 RB----- 8----- KE03B------ JH2KE03B-8K100001------ JH2KE03B-8K199999------ 2008----------- 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 RB----- 9----- KE03A------ JH2KE03A-9K200001------ JH2KE03A-9K299999------ 2009-2011------ 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 RB----- C----- KE03A------ JH2KE03A-CK300001------ JH2KE03A-DK499999------ 2012----------- 1------ 24 BHP, 18 kw------
    Honda CRF 150 RB----- D----- KE03A------ JH2KE03A-DK400001------ JH2KE03A-DK499999------ 2013----------- 1------ 24 BHP, 18 kw------
    Honda CRF 150 RB----- E----- KE03A------ JH2KE03A-EK500001------ JH2KE03A-DK499999------ 2014-2015------ 1------ 24 BHP, 18 kw------

    My issue comes from the year column,

    the first to rows are ok, but its any row that contains multiple years i.e the third row down is 2009-2011,

    what i need to be able to do is to insert two empty rows below that row, as the cell that "2009-2011" was in will now have to contain "2009" then the two cells below need to be "2010" and "2011" respectively, and in an ideal world, fills in the data identically to in the other columns ( i hope that makes sense lol)


    So basically this row:


    Honda CRF 150 RB------ 9------ KE03A------ JH2KE03A-9K200001------ JH2KE03A-9K299999------ 2009-2011------ 1------ 22,6 BHP, 16,6 kw------



    Becomes:

    Honda CRF 150 RB------ 9------ KE03A------ JH2KE03A-9K200001------ JH2KE03A-9K299999------ 2009------ 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 RB------ 9------ KE03A------ JH2KE03A-9K200001------ JH2KE03A-9K299999------ 2010------ 1------ 22,6 BHP, 16,6 kw------
    Honda CRF 150 RB------ 9------ KE03A------ JH2KE03A-9K200001------ JH2KE03A-9K299999------ 2011------ 1------ 22,6 BHP, 16,6 kw------



    I dont know if this is possible by a formula (probably not), i have no experience with macros or vba but i am willing to learn lol

    thanks for any help in advance,

    Warren.

    ps. I have attached an excel version of the sample if it helps
    Attached Files Attached Files
    Last edited by warrenr6; 09-03-2016 at 05:29 PM. Reason: HARD TO READ DATA

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Insert blank rows based on a cell value

    Hi Warren,

    Run this code while looking at your sheet (make a backup first), and see if it does what you are asking for.

    Please Login or Register  to view this content.
    Fill In Row data across dash years.xlsm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Insert blank rows based on a cell value

    I'm late ... well this was what i managed (to be copied in the sheets' vba module):
    Please Login or Register  to view this content.
    Last edited by rollis13; 09-03-2016 at 07:11 PM.

  4. #4
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    Hi guys,

    thanks for the replys,

    how do i do this i have never done anything with codes or vba`s,

    sorry completely new to this way of doing things,

    regards,

    warren.

  5. #5
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Insert blank rows based on a cell value

    Always use a copy of your file for testing.
    Click on the sheets' Tab and choose View Code and then paste my code in the right panel.
    Or press Alt+F11 to go to the VBA panel. DoubleClick on your sheets' name on the left and then paste my code in the right panel.
    Go back to your sheet and press Alt+F8 to choose a macro to be run.

    MarvinP has attached a copy of his file.

  6. #6
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    Hey,

    i tried it on the small sample range and it worked perfectly, however when i tried to do it to the full file it said script out of range?

    would you like me to attach the full file?

    would it be because a few odd year cells are empty?

    regards,

    warren

  7. #7
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Insert blank rows based on a cell value

    Yes, it's because the cell is empty.
    Change this line of code:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    Hey

    thanks for that,

    i changed what you said,

    when i ran the code, it added 796 new rows but an error came up that said "Type Mismatch"

    Any ideas? Am i doing something wrong?

    regards,

    Warren.

  9. #9
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Insert blank rows based on a cell value

    If you don't state where the Debug stops and the value of the variables at that moment it's hard to realize what triggers the error.
    So, now it's better if you attach the full file as you suggested in your post #6.

  10. #10
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    Hi rollis13,

    sorry for that,

    im not 100% where it stopped, i thought maybe i had entered something wrong, i will attach the file for you to see here, i really do appreciate all your help,

    thanks,

    warren

  11. #11
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    i will have to do it in a few parts as the file exceeds what is allowed to be uploaded

  12. #12
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    file 1 and 2
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    file 3

    thanks,

    regards,

    warren.
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Insert blank rows based on a cell value

    Yes, you have some other cells with offending data. To help finding them you can use the macro "Validate_Years" and take note of the offending cells.
    Then you can search and modify them; use key F5 and indicate the coordinates of the cell in the field "Reference" ex. F1855 then correct the data.
    Once finished you may launch the macro "Duplicate_Years".
    As before, copy all the code in the sheets' vba module.
    Please Login or Register  to view this content.
    Last edited by rollis13; 09-05-2016 at 07:22 AM.

  15. #15
    Registered User
    Join Date
    10-23-2012
    Location
    belfast
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Insert blank rows based on a cell value

    Hi Rollis13,

    that looks to have worked perfectly, i really appreciate your help,

    best regards,

    Warren.

  16. #16
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: Insert blank rows based on a cell value

    Glad having been of some help

+ 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] Macro needed to insert blank rows below row based on value in cell in row
    By lauragoodwin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2015, 12:41 PM
  2. [SOLVED] Insert Blank Rows between existing data based on dups in sheet2
    By Melissa Camp in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-29-2014, 07:07 AM
  3. [SOLVED] Macro to Insert blank rows based on condition
    By Nikkishr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2012, 03:32 AM
  4. Insert 2 blank rows and sum columns based on cell value change
    By parreola in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 11:14 PM
  5. insert a blank rows based on cell value
    By pani_hcu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-28-2009, 09:47 AM
  6. insert blank rows based on columns a values numerically
    By elkhole in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-18-2009, 04:57 AM
  7. Macro to insert blank rows based on data above
    By MattLinkus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2007, 06:35 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