+ Reply to Thread
Results 1 to 18 of 18

Macro to move rows from one sheet to another based on cell value

  1. #1
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Macro to move rows from one sheet to another based on cell value

    I have looked at/tried several macros from several threads but they all seem to do some of what I need but not everything. The last one did successfully move a row from one sheet (ITEMS) to another sheet (SOLD) based on the cell value of the STATUS column. (If 's' then move to SOLD sheet. But each time it moved a row it deleted the previous ones instead of 'adding' to the existing list.

    So essentially I have a spreadsheet with 3 sheets....ITEMS, DONATED, SOLD. The ITEMS page may contain unlimited rows. I want to be able to enter a sold status ('s') in the STATUS column of a row and then....

    1. The entire row should move from the ITEMS sheet to the SOLD sheet. There will already be a TITLE ROW on the first row of the SOLD sheet so the inserted rows should start at 2 but when a row is moved to this sheet it should be added to the existing list not delete anything on the list. There will also be a TOTALS row at the bottom that will have formulas to total the SOLD items values etc. So the rows moved to this sheet should be inserted BETWEEN the TITLE row and the TOTALS row.
    2. The ITEMS sheet will not longer contain the SOLD row item and thus the other items in the list will shift upwards.

    The same would be true if the STATUS column is 'd'.....except the entire row would move to the DONATED sheet.

    Ideally I would also like to be able to move a row BACK to the ITEMS sheet from the SOLD or DONATED sheet if the Status of S or D is removed from the STATUS column on the Sold or Donated sheets.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    Thanks for the reply.
    I have attached four spreadsheets.
    Shell - The basic shell (including formulas) that I would start with
    Initial - The initial entry of client's data
    Updated - Additional entries after items have sold.....Updates are shown in ITEMS sheet and comments showing where the rows should move to.
    MOVED - What sheet should look like after rows have been moved. Note, there are formulas on the different pages with relative sums etc that need to change accordingly.
    In this example, after the rows have moved, I've entered information on the SOLD page in columns g,i,j,k,m,t that were used in formulas for columns h,l,n,o,p,q,r,s,u.

    So I need
    1. Rows to move so they are added to the bottom of the most recent list
    2. When rows move, for the empty row to be deleted and other rows moved up.
    3. SOLD sheet formulas in new columns to work for the newly moved-in rows
    4. TOTALS formulas in SOLD sheet to be relative to newly moved-in rows.

    Thank you for your help.
    Attached Files Attached Files

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    After I replaced the Totals Formulas like:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    to
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    then the routine, finally, seems to have worked - check it out

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    So.....
    I went to my INITIAL workbook and changed the SOLD sheet total formulas like you said.
    Then I went to the ITEMS sheet, right clicked, selected view code, copied the above code into the sheet.
    Then I changed the Status to S......and nothing happened....

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    Did you run the program? Or, are you expecting it to trigger from the status entry??

  7. #7
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    Sorry,I WAS expecting it to trigger from the status entry.
    I would be fine to have it manually run.....isn't there a way to add a 'update button' that I could click to run the macro?
    Sorry, I'm such a newbie at this. Your help has been invaluable!

  8. #8
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    running the macro manually worked great btw

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    Great! - glad it worked

  10. #10
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    Hi, Sorry to bother again,
    but it appears when I run the macro in the ITEMS sheet that the formula in the last column in the SOLD sheet
    does not get copied into the cell like the others do. I tried to decipher the code and thought I just needed to increase
    the range in this code from 15 to 16 but it didn't help.

    Set R = ws.Cells(3, 6).Resize(1, 15): R.Copy ws.Cells(2, 6)

    Also, the ITEMS sheet entries started in line 3 in my example but that was inadvertent(sorry!).
    So now when I put something in line 2 (the first line under the column headings) it doesn't transfer over.

    I think changing the code

    For i = wi.Range("B" & Rows.count).End(xlUp).Row To 3 Step -1

    from 'To 3' to 'To 2' might fix the problem but I'm not sure.

    Thanks.

  11. #11
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    Also, it doesn't seem to take the value of column 6 (S/H fee for buyer) over either. Again, I think its a range thing

    Set R = wi.Rows(i): R.Cut: ws.Cells(2, 1).EntireRow.Insert
    Set R = ws.Cells(3, 6).Resize(1, 15): R.Copy ws.Cells(2, 6)


    but the changes I make seem to make it worse.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    Yeah - that along with the 16 in the resize should fix it all else being the same.

  13. #13
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    The first fix worked for picking up the missing row. Already tested it out.

    But changing the range to 16 does not bring in the formula from Sara's NET (last column 21 in SOLD sheet)
    .....and the S/H column (column 6,last one on the ITEMS sheet)does not cross over either.....

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    Have you got a different sample? There is no formula in my updated copy for F2. The U2 carries up for me

  15. #15
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    Sorry. I did make changes.
    Fortunately I've figured everything out!
    .....
    but I have a 'new' problem that I've almost solved but not perfectly.
    I created another sheet for my client to just have the info she needs.
    basically the item description, sold price, and the date paid and check #.
    I have figured out how to copy the information to the new sheet with one problem.
    The information is not in consecutive columns. No problem.
    Here's my code.
    Set R = ws.Cells(i, 1).Resize(1, 3): R.Copy: wc.Cells(2, 1).Resize(1, 3).Insert
    Set R = ws.Cells(i, 15).Resize(1, 4): R.Copy: wc.Cells(2, 4).Resize(1, 4).Insert

    HOWEVER, the first three columns copied are entered values. Then I skip some columns and copy four more columns starting at column 15. Columns 16-18 are also entered values so they copy fine but column 15 is a value derived from a formula so its copying over the formula not the actual computed value. I think I should probably use pastespecial but I don't know how....

    Thanks.

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    Maybe:

    Please Login or Register  to view this content.
    added after the inserts

  17. #17
    Registered User
    Join Date
    11-13-2017
    Location
    Raleigh, NC
    MS-Off Ver
    2011
    Posts
    23

    Re: Macro to move rows from one sheet to another based on cell value

    Perfect! Thank you!

  18. #18
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to move rows from one sheet to another based on cell value

    You're welcome!

+ 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. Move rows based on cell value with a Macro
    By bkrbali in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-21-2016, 12:29 AM
  2. [SOLVED] Macros To Move Multiple Rows To Another Sheet And Macro To Move Single Rows To DAX Table
    By jcaynes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2013, 05:08 PM
  3. Excel 2011 macro to move rows from one sheet to another and group based on criteria
    By jasond02 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2013, 05:21 PM
  4. VBA CODE to move rows from one sheet(1) to another sheet(2) based on data in cell
    By fozzieulo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 02:43 PM
  5. Macro to move rows from one sheet to another sheet based on a cell vaule
    By d55272 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-09-2012, 03:33 PM
  6. Replies: 1
    Last Post: 08-06-2012, 10:49 AM
  7. How to move rows to new sheet based on cell data
    By jacobmast in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2011, 12:18 AM

Tags for this Thread

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