+ Reply to Thread
Results 1 to 7 of 7

VBA Add rows or split cell according to another cell value

  1. #1
    Registered User
    Join Date
    08-11-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    43

    VBA Add rows or split cell according to another cell value

    Hello,
    I hope someone can help me.
    I'm trying to find a way to split a cell to rows. The no. of rows should be the same as a value inserted on another cell.
    I tried to add a picture, hope it will work.
    Thanks in advance.

    Excel.jpg
    Attached Images Attached Images

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,234

    Re: VBA Add rows or split cell according to another cell value

    Hello josekr80

    Rule No 1 in Excel...Avoid merged cells at all costs they just cause havoc with VBA...
    Secondly...A sample upload means so so much more than images...We have no test file to make us of...
    The no. of rows should be the same as a value inserted on another cell.
    What cell what sheet etc etc...
    In your sample upload give a Before|After scenario so that we understand what is required...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: VBA Add rows or split cell according to another cell value

    Hi there josekr80

    try the attached file and tell me what you think.


    LE:
    I had no other idea but to write code that follows the normal excel behavior. Here is the code I wrote:

    Please Login or Register  to view this content.
    The code is triggered as any cell is changed in the sheet.
    Attached Files Attached Files
    Last edited by bulina2k; 08-11-2019 at 12:08 PM.
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,820

    Re: VBA Add rows or split cell according to another cell value

    Sorry for off-topic interjection:

    Although there is no official rule regarding this behaviour, we request that wherever possible both the question AND the answer be provided in substantive detail here within the thread. An attached workbook is an excellent aid for posing a question and offering a solution, but solely doing that with no in thread explanation makes it difficult for researchers to understand or consider the Q & A of this thread without downloading what may be a pointless doc to them, if they can do that at all. Doing that also hides the content from search engines so others may never benefit from this.

    I'm sure you understand.

    EDIT: Thanks for adding extra details.
    Last edited by AliGW; 08-11-2019 at 12:13 PM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    08-11-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    43

    Re: VBA Add rows or split cell according to another cell value

    Hey, it works very good.
    I had only 1 issue:when you insert the value 2,3,4 ... the number of rows changes accordingly, that is good. But if you insert 3, and try to change it to 1 or zero, the number of rows stays the same. I mean, you can't bring it back to the original number of rows.
    And one more thing, I tried by myself to add more rows on the top of the sheet, for header, etc... and it affects the code. I couldn't change the code by my self. Is there any chance to get a file that the table starts on row number 6? So I''l have some space on the top?
    Thanks a lot in advance.
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    861

    Re: VBA Add rows or split cell according to another cell value

    Hi there Josekr,

    I modified the code in the NEW.xlsm file that you attached. Now the code takes into consideration the extra column '# of Samples' that you put there.
    Now the value 1 takes away the extra rows.
    The 2 lines at the end of the code, need the first cell address of the table. (A7) so if you add/subtract extra rows, please modify accordingly.
    Inserting rows does not damage the code but inserting columns, especially before the 'no. of bad parts' column, yes it makes the code useless.
    So, some requirements for this code to work would be:
    - don't insert columns before the triggering column (that is the F column now)
    - the Part ID must be filled before using this code.


    The modified code is:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-11-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    43

    Re: VBA Add rows or split cell according to another cell value

    Thank you very much for your time, especially for bulina2K that solved this issue.
    It will help me a lot, and I'm learning a lot here.
    Have a great day / night.

+ 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] VBA Split Cell Contents to New Rows & Copy Cells containing single values to the new rows
    By jaimelwilson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-14-2017, 05:30 PM
  2. [SOLVED] SPLIT cell to rows
    By confusus in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-17-2017, 12:10 PM
  3. Split up a cell into rows
    By araki in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2016, 12:01 PM
  4. Split cell value in rows
    By sserge in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-08-2015, 08:32 PM
  5. Split one cell value into Rows
    By araviintl in forum Excel General
    Replies: 1
    Last Post: 05-08-2014, 01:31 PM
  6. Macro to split a cell data into rows and copying other cells as it is in rows
    By shaan65 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-26-2010, 12:45 AM
  7. Macro to split a single cell data into rows and copying other cells as it is in rows
    By Pankaj Sonawane in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-25-2010, 07:09 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