+ Reply to Thread
Results 1 to 7 of 7

Move selected cells to previous row

  1. #1
    Registered User
    Join Date
    10-07-2004
    Posts
    4

    Move selected cells to previous row

    I have a sreadsheet like this (shown in CSV format), Only the first column is really relevant.

    1,a,b,c
    2,d,e,f
    3,g,h,i
    3R,j,k,l
    4,m,n,o
    5,p,q,r
    5R,s,t,u

    I want to detect all rows with the R on the end of the text in the first column and shift that row to the end of the preceding row and delete the "R" row, producing this:

    1,a,b,c
    2,d,e,f
    3,g,h,i,3R,j,k,l
    4,m,n,o
    5,p,q,r,5R,s,t,u

    Is there any easy way of doing that automatically please? There will be many thousands of rows so I don't want to have to do it manually.
    Last edited by pmolsen; 08-30-2012 at 06:47 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Move selected cells to previous row

    Can you correct your example? It does not appear you DID what you said, which would be take line 5 and remove the ,r at the end and then move the remaining string UP into the row above. You appear to have just merged rows 5 and 6 and left the ,r in there.


    Even better, make a longer example and upload it in an Excel sheet since that's where we'll do the work.

    Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook. Use BEFORE/AFTER examples just like you did above, but make 100% sure it is the right results.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-07-2004
    Posts
    4

    Re: Move selected cells to previous row

    What I said is a bit confusing. I also don't really want the R cell included but thought that would make it simpler.
    Attached is a file showing what I really want.

    I have repeated the data in the file for the example only. I only want the one lot of data after the macro runs.

    I also had to change the unique rows to use eg. 40.1 instead of 40R. I discovered that Excel does not sort them one after the other even if I change all cells to text (Windows Explorer sorts files named like that correctly).

    convert.xls
    Last edited by pmolsen; 08-31-2012 at 02:59 AM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Move selected cells to previous row

    TO do it "automatically" means using a macro.

    Please Login or Register  to view this content.

    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.

  5. #5
    Registered User
    Join Date
    10-07-2004
    Posts
    4

    Re: Move selected cells to previous row

    That is brilliant! Thank you very much for the assistance.

    Oops. One slight problem when I run it for real. My spreadsheet has various header and comment rows before the data. As a result the macro produces a Type Mismatch error.

    I updated it as follows and it is now fine:
    Please Login or Register  to view this content.
    Last edited by pmolsen; 08-31-2012 at 08:58 PM.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Move selected cells to previous row

    I have marked this thread solved for you.
    In the future please select Thread Tools from the menu above and mark the thread as solved. Thanks.

  7. #7
    Registered User
    Join Date
    10-07-2004
    Posts
    4

    Re: Move selected cells to previous row

    I've run into another problem. It's my fault for not giving all the information. The spreadsheet actually contains values in columns H onwards. When I run with no data there, like in my original sample file, it works fine. When I have data there it only works for for the last of the "special" rows. The special rows get deleted but their data does not get put in columns E-G.

    Ended up changing to this. I'm sure the 3 assignment statements can be combined but I could not figure out how to combine them.

    Please Login or Register  to view this content.
    Last edited by pmolsen; 08-31-2012 at 11:44 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