+ Reply to Thread
Results 1 to 17 of 17

Macro to move rows from one sheet to another sheet based on a cell vaule

  1. #1
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

    Question Macro to move rows from one sheet to another sheet based on a cell vaule

    TPM Cards.xlsx

    I am trying to move rows from one sheet onther sheet if a cell has the status of "complete". I have tried the record macro but I am obviously doing something wrong because it will not add it to the end of the sheet, just replaces what was in that rw. Any help would be greatly appreciated. It is driving me crazy.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

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

    Its better to post a sample workbook of what your wanting to do.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    At the risk of sounding really stupid - I don't know how to???? Tried to copy & paste but that doesn't seem to work

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

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

    Are you wanting to delete the row from the Table after adding it to Complete?

  5. #5
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    Yes, that would be great

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

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

    Give this a try, Im guessing every time you run the macro you want to keep adding to the bottom of Completed sheet


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    Thank you so much. Will give it a try tomorrow.

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    Ok test on a copy of your wb

  9. #9
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    I am getting a Compile error: Syntax Error and highlighted in blue is "End SubSub abc()". I suspect it may be the double sub but when I delete one of them I still get a syntax error. Thanks in advance for all of your work & help.

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    Are you sure u copied it correctly?

  11. #11
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    Below is a copy of what I have. Should the Sub Complete() at the beginning and the two End Sub at the end be there? They came up automatically so I pasted in between them.


    Sub Complete()
    Option Explicit
    Sub abc()
    Const shTable As String = "Table"
    Const shComplete As String = "Complete"
    Dim RangeToDelete As Range
    Dim lastrow As Long, ptr As Long, ii As Long, n As Long
    Dim aComplete()

    With Worksheets(shTable)
    lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
    ReDim aComplete(1 To lastrow, 1 To 10)
    For ptr = 1 To lastrow
    If .Cells(ptr, "E") = "Complete" Then
    If RangeToDelete Is Nothing Then
    Set RangeToDelete = .Cells(ptr, "A")
    Else
    Set RangeToDelete = Union(RangeToDelete, .Cells(ptr, "A"))
    End If
    n = n + 1
    For ii = 1 To 10
    aComplete(n, ii) = .Cells(ptr, ii)
    Next
    End If
    Next ptr
    If Not RangeToDelete Is Nothing Then
    RangeToDelete.EntireRow.Delete
    End If
    End With

    If n > 0 Then
    With Worksheets(shComplete)
    With .Range("a" & Rows.Count).End(xlUp).Offset(1).Resize(n, UBound(aComplete, 2))
    .Value = aComplete
    .Borders.LineStyle = xlContinuous
    End With
    End With
    End If
    Erase aComplete
    End Sub
    End Sub

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    Remove sub complete at the top and one of the end sub at the bottom

  13. #13
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    Now no error mesages but nothing happens. When I use the step into, the sub complete is gone, there is a line all the way across the sheet under option explicit and the sub abc is highlighted in yellow with a yellow arrow beside it. I must be doing something wrong but I have no clue what.

  14. #14
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520
    I'm away from my computer, it'll be a few hours before I can get back to it.

  15. #15
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

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

    In the VBE editor click Run then click reset, place your cursor at the start of Sub abc() then click Run then Run.
    Last edited by WasWodge; 10-07-2012 at 05:56 PM.
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  16. #16
    Registered User
    Join Date
    10-06-2012
    Location
    Seagrove, North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    6

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

    Thanks for the help but nothing is happening - but no error messages

  17. #17
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

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

    Mike's code is working fine for me in a copy of the workbook you put in post #1.

    I have placed a copy of the workbook with the macro in place in the link below and have assigned it a shortcut of Ctrl-Shift-J to run the macro.

    Obviously make sure that you have enabled the Macro's when you open the workbook
    Attached Files Attached Files
    Last edited by WasWodge; 10-09-2012 at 03:35 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