+ Reply to Thread
Results 1 to 14 of 14

Macro to split a single cell data into rows and copying other cells as it is in rows

  1. #1
    Registered User
    Join Date
    07-31-2010
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Macro to split a single cell data into rows and copying other cells as it is in rows

    Hi,

    I want to split a cell into rows and copy the rest of the data as it is in the row. For Eg. we have data in rows as (cell A1=Apple, cell B1=Ball, cell C1=Cat, cell D1=Dog, Fish, Rat, cell E1=Elephant). Now I want to split cell D1 in 3 rows(D1,D2,D3) without the commas and copy cell A1 into A2 & A3, B1 into B2 & B3, C1 into C2 & C3 & E1 into E2 & E3 as it is.

    This will not be constrained upto single row, there may be multiple rows containing more data in a single cell which needs to be splitted in rows.

    First I want to search which cell in the row contains the string with commas and then split it in rows.

    I am attaching a excel sheet for your reference.

    Regards,
    Pankaj
    Last edited by Pankaj Sonawane; 08-10-2010 at 04:29 PM.

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

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Pankaj Sonawane,

    Detach/open workbook Pankaj Sonawane - EF 739727 - SDG10.xls and run macro SplitData.
    Attached Files Attached Files
    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
    07-31-2010
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Thank u for your quick reply Stan,

    I did this same thing and now getting where I am wrong. Now my problem is a little different here. I want to search the cell in the row containing string which has commas in it and then apply split to it (It will be like start searching from 1st row if string with commas is present apply split else move to next row, and this will go on till the last row)

    After applying the split function I want the macro to copy whole data on next sheet by opening a new worksheet called Sheet2. This is getting a little complicated for me.

    I have attached the new worksheet for your reference.

    Regards,
    Pankaj
    Last edited by royUK; 08-10-2010 at 09:31 AM.

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

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Pankaj Sonawane,

    Detach/open workbook Pankaj Sonawane - EF 739727 - V2 - SDG10.xls and run macro SplitData.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-31-2010
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Hi Stan,

    First I would like to take time to thank you for helping me getting the macro in right manner, however I haven't yet succeeded in this.

    I am attaching the original sheet which I am working on and below are the details given:

    1. I need to split column D (as previously said) and copy rest of the data in the rows as it is.
    2. Sheet1: original data
    3. Sheet2: Target result to be copied
    4. Sheet3: First Macro
    5. Sheet4: Second Macro

    Below are the problems I am facing while running the macro:

    1. When I run the first macro i.e. in Sheet3 where we are saying " If MyC > 0 Then" it is giving me an error on row 18 as given and marked yellow in Sheet3. Also, with error it executes the macro, splits cell D, copies rest of the data as it is in the rows, but does not copy row no 3, 6,9 and so on i.e. it does not copies the row if cell D in that row does not consists comma in it.

    2. When I run the second macro i.e. in Sheet4 where we are saying " If MyC >= 0 Then" it is giving me an error on row 16 as given and marked yellow in Sheet4. This second macro executes with error and copies very less data(you will come to know once you execute it at your side)

    Result Expected: I want to split the string in cell D whihc consists commas and let rest of the data be copied as it is in the rows. If cell D contains a string/Stmt which contains no comma that whole row should be copied as it is continuing with splitting of data for other rows if commas exists for them.

    Hope you get my problem as I have mentioned it as simpler as I can

    Regards,
    Pankaj
    Last edited by royUK; 08-10-2010 at 09:30 AM.

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

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Pankaj Sonawane,

    Detach/open workbook Pankaj Sonawane - EF 739727 - V3 - SDG10.xls and run the updated macro SplitDataV3.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-31-2010
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Stan,

    The macro is still not copying row no. 3, 6, 8, 9, 10 etc from my original sheet.

    I am still figuring that out, see if you can work it out.

    Regards,
    Pankaj

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

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Pankaj Sonawane,

    Missed that.

    Detach/open workbook Pankaj Sonawane - EF 739727 - V4 - SDG10.xls and run macro SplitDataV4.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-31-2010
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Thank you very much for your time Stan.

    I did the same here by using Elseif function which you gave me in this doc. Will get in touch if I need some more help

    Could you please let me know how can I remove all excel sheets from here which I attached for your reference?

    Regards,
    Pankaj

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

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Pankaj,

    Could you please let me know how can I remove all excel sheets from here which I attached for your reference?
    Contact one of the Moderators.

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Why should they be deleted. You aren't warned to delete any sensitive information before attaching. Removing the files will make it difficult for others to follow the Thread
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  12. #12
    Registered User
    Join Date
    07-31-2010
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Yeah I knew that. I just attached the original file which I was working on to give the real feeling of the data.

    I just want to delete last 4 excel sheets which contains the original data. The sheets prior to these 4 sheets are the e.g. of my original data.

    According to me deleting these 4 sheets will not create any problem to the thread followers to get the proper solution and I will also be satisfied.

    Could you delete these 4 sheets please?

    Regards,
    Pankaj

  13. #13
    Registered User
    Join Date
    08-23-2010
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    4

    Thumbs up Re: Macro to split a single cell data into rows and copying other cells as it is in r

    Hi there !

    You just saved me so much time, I really appreciate it.
    I was using macros, which you provided to Sonawane and it works great for my data template.

    I was wondering if you can help me out with extra feature, if possible. I want to apply same macros to 2 cell data and not just one, like you have with Sonawane file.

    I have attached excel data template.

    thank you so much !









    Quote Originally Posted by stanleydgromjr View Post
    Pankaj Sonawane,

    Missed that.

    Detach/open workbook Pankaj Sonawane - EF 739727 - V4 - SDG10.xls and run macro SplitDataV4.
    Attached Files Attached Files

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

    Re: Macro to split a single cell data into rows and copying other cells as it is in r

    stealthman,

    This original Post has been closed.

    You should start your own NEW post, and someone will assists you.
    Last edited by stanleydgromjr; 08-25-2010 at 07:11 PM.

+ 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