+ Reply to Thread
Results 1 to 6 of 6

Move row to new sheet based on a value and delete row that was moved.

  1. #1
    Registered User
    Join Date
    08-21-2019
    Location
    Columbia, MO
    MS-Off Ver
    365
    Posts
    2

    Move row to new sheet based on a value and delete row that was moved.

    I've been trying to work though this problem and seem to have most of it solved. I can get excel to move all matching rows to a new sheet based on a value in column 5 or column E. What I would like to happen is that after the matching rows have been moved to sheet two, it deletes the row(s) that were moved from sheet 1. Any thoughts on how I can do this? Here's the code I'm using. Sheet 1 has 5 columns A thru E.

    Private Sub CommandButton1_Click()
    a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 To a
    If Worksheets("Sheet1").Cells(i, 5).Value = "Missing" Then
    Worksheets("Sheet1").Rows(i).Copy
    Worksheets("Sheet2").Activate
    b = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
    Worksheets("Sheet2").Cells(b + 1, 1).Select
    ActiveSheet.Paste
    Worksheets("Sheet1").Activate

    End If

    Next

    Application.CutCopyMode = False
    ThisWorkbook.Worksheets("Sheet1").Cells(1, 1).Select
    End Sub

  2. #2
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Move row to new sheet based on a value and delete row that was moved.

    try
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-21-2019
    Location
    Columbia, MO
    MS-Off Ver
    365
    Posts
    2

    Re: Move row to new sheet based on a value and delete row that was moved.

    Yes, that worked, I appreciate it. Is there a way to make it move all instances of "Missing" at one time? As your code works, I have to push the button multiple times to move all the lines. If not, I can live with it. Thanks again for your help!

  4. #4
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Move row to new sheet based on a value and delete row that was moved.

    it does when I try

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: Move row to new sheet based on a value and delete row that was moved.

    When deleting rows like that you need to loop from the bottom up.
    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: Move row to new sheet based on a value and delete row that was moved.

    Or a slightly simplified version
    Please Login or Register  to view this content.

+ 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 up data row to blank row and clearcontents the moved row
    By RIZVI in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2019, 11:34 AM
  2. Replies: 5
    Last Post: 06-20-2014, 08:13 AM
  3. [SOLVED] Move entire row from one sheet to another based on cell value & delete the original row
    By ceciliacrawford in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-08-2014, 03:12 AM
  4. [SOLVED] Move row from one sheet to another based on condition and then delete - please help
    By junijl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2013, 10:32 AM
  5. [SOLVED] Copy row from sheet 1 to next row in sheet 2. delete from sheet 1 and move rows up
    By papabob1954 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-16-2012, 09:38 PM
  6. Macro to move entire row if cell contains a specific word and moved to sheet 2
    By Astarte in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2011, 09:21 AM
  7. Moved data to new sheet based on list selection
    By scronk in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-18-2005, 04:05 AM

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