+ Reply to Thread
Results 1 to 15 of 15

Splitting contents of 2 cells into rows

  1. #1
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Splitting contents of 2 cells into rows

    I've done some searching and can't find the solution I'm looking for.
    I'm trying separate the contents of 2 cells - Columns C and D - into their own separate rows.
    I would like it so Username1(column c) and U1(column D) stay in the same row and Username2 and U2 are in the their own separate row and so on.
    Columns C and D do not have a fixed number of ID's - it ranges to up over 10 usernames and Id's.
    Hope I explained that ok? :-)
    Any help would be much appreciated.
    Attached Files Attached Files
    Last edited by blackls1z; 08-22-2012 at 09:33 AM.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Splitting contents of 2 cells into rows

    blackls1z,


    Detach/open workbook ReorgData Split colC and colD together - blackls1z - EF854534 - SDG15.xlsm and run the ReorgData macro.


    If you want to use the macro on another workbook:


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


    Please Login or Register  to view this content.

    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


    Then run the ReorgData macro.
    Last edited by stanleydgromjr; 08-21-2012 at 03:17 PM.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Splitting contents of 2 cells into rows

    Thanks! I must be doing something wrong because I get a compile errror: Sub or Function not defined. The line Sub ReorgData() is highlighted yellow with a yellow arrow to the left

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Splitting contents of 2 cells into rows

    blackls1z,

    What version of Excel are you using?

    You posted an Excel 2007 workbook. But, your handle information for blackls1z indicates that you are uisng Excel 2003.


    And, I responeded with an Excel 2007 workbook.

    Did you try opening and running my attached workbook?

    Or, did you try pasting the macro code in another workbook?

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Splitting contents of 2 cells into rows

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Splitting contents of 2 cells into rows

    Try this,Click on the button and see if it is what you need.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  7. #7
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Splitting contents of 2 cells into rows

    I'm actually running 2010.

    I just downloaded the file you uploaded and did an alt-F8 and run the ReorgData Macro. I've attached a screen shot of what happens.

    Thanks for all the help!

    Quote Originally Posted by stanleydgromjr View Post
    blackls1z,

    What version of Excel are you using?

    You posted an Excel 2007 workbook. But, your handle information for blackls1z indicates that you are uisng Excel 2003.


    And, I responeded with an Excel 2007 workbook.

    Did you try opening and running my attached workbook?

    Or, did you try pasting the macro code in another workbook?
    Attached Images Attached Images

  8. #8
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Splitting contents of 2 cells into rows

    That works great with the file you uploaded but I get a type mismatch error when I try to paste the code into another file.
    It seems to get hung up on this line:
    txt = Join$(Application.Transpose(.Columns("c")))


    Quote Originally Posted by jindon View Post
    Try
    Please Login or Register  to view this content.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Splitting contents of 2 cells into rows

    Quote Originally Posted by blackls1z View Post
    That works great with the file you uploaded but I get a type mismatch error when I try to paste the code into another file.
    It seems to get hung up on this line:
    txt = Join$(Application.Transpose(.Columns("c")))
    The I need to see the file.

  10. #10
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Splitting contents of 2 cells into rows

    Here is the basic structure of it - I just tossed in false data.....but get the same error when using the real file.
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Splitting contents of 2 cells into rows

    Change to
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Splitting contents of 2 cells into rows

    Sweet! That works for all but the 3rd worksheet for some reason. Everything appears to be the same as the other two worksheets so I'm not sure what Is going on with that.
    It gets hung up at : b(n, 4) = Trim$(Split(a(i, 4), ",")(ii))
    It is the longest of the 3 worksheets - I did notice that a couple of the id's in column C have a space in them - not sure if that would cause it to error out.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Splitting contents of 2 cells into rows

    That's most probably number of rows in C is greater than D.
    Try this and see.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-21-2012
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Splitting contents of 2 cells into rows

    You are a genius! That was the problem! Thanks a bunch!

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Splitting contents of 2 cells into rows

    You are welcome and don't forget to mark the thread as "Solved"

+ 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