+ Reply to Thread
Results 1 to 16 of 16

Macro to split cells into inserted new row and copy the rest of the row into it.

  1. #1
    Registered User
    Join Date
    11-01-2007
    Posts
    5

    Macro to split cells into inserted new row and copy the rest of the row into it.

    Hi,

    I really hope someone can help me?

    I need a macro that can search text cells in column L for a space delimiter, then if the space is present, to split that cell into a row inserted below it, then copy the information in the rest of the row down. I'm not really up on my VBA and this is pretty complicated!

    It's for a large range of data, so can't really be done manually with transpose.

    Thanks in advance!

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Hello e01nd,

    I think the code below will do what you're requesting. Place it into the worksheet's vbe module (right-click on the sheet tab in question, click View Code, paste this code into the empty white space on the right of the VBE window). You can then run the code via the macros menu or by pressing ALT+F8.
    Please Login or Register  to view this content.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    A slightly cleaner version using variables instead of repeating the same functions:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523
    Hi there,

    Assuming the data is continuous from cell L2, the following should do the trick.

    HTH

    Robert


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-01-2007
    Posts
    5

    Thanks!

    Hi Both,

    Thanks for these. Trebor, your code seems to work best! Would it be possible to copy down the data in the rest of the row too?

    Many thanks for your time and energy!

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523
    Hi there,

    Glad to hear it worked (almost).

    Is there a certain column where the data always stops at or is it variable (if it's variable, is the data continuous across the sheet)?

    Regards,

    Robert
    Last edited by Trebor76; 11-01-2007 at 06:53 PM.

  7. #7
    Registered User
    Join Date
    11-01-2007
    Posts
    5
    Hi Robert,

    The last column is N.

    Thanks a million!!

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523
    Hi there,

    I've made the following code dynamic (it finds what the last column with data in it is) and therefore more flexible.

    Let me know how it goes.

    Robert

    Please Login or Register  to view this content.
    Last edited by Trebor76; 11-01-2007 at 07:47 PM.

  9. #9
    Registered User
    Join Date
    11-01-2007
    Posts
    5
    Hi Robert,

    Again, that works great. Only problem is that it's not copying down the data before column L, only data afterwards.

    I'm amazed at how quickly you're churning these out. Your help is really appreciated!

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523
    Hi there,

    Hopefully this should be it.

    Regards,

    Robert

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-01-2007
    Posts
    5

    Thank You!

    Works perfectly!!!

    Thank you so much!!

  12. #12
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523
    You're very welcome!!

  13. #13
    Forum Contributor
    Join Date
    12-12-2006
    Location
    New Zealand
    Posts
    151
    Another way:

    Please Login or Register  to view this content.
    Last edited by Reafidy; 11-02-2007 at 06:35 PM.

  14. #14
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    The SPLIT function!!! ::smacking self in head::



    Nice work!

  15. #15
    Registered User
    Join Date
    11-01-2012
    Location
    Silverdale, Washington
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Macro to split cells into inserted new row and copy the rest of the row into it.

    I'm using this, and it's great if there are only 2 items in the cell. What if there are 1-5 delimited values in the cell/range? My spreadsheet has columns A-AR, Rows 1-29 (for now). In Column R, I have multiple delimited values. I'd like to add a row for each one, but leave other cells from other columns blank. What I'd really like is to be able to split multiple columns, as I have this happening in a couple of columns. Any help? Thanks!

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to split cells into inserted new row and copy the rest of the row into it.

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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