+ Reply to Thread
Results 1 to 3 of 3

Need help with a macro to move row to another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    04-05-2011
    Location
    US, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    2

    Need help with a macro to move row to another worksheet

    I need help with a macro to move rows to different worksheets. For example, If I put in Delivered, I want the row moved to a "Delivered" worksheet. If I put in Declined, I want the row moved to a "Declined" worksheet. I have been able to successfully get one of these to work at a time, but I need both of these to work in a single Macro. Help anyone? Here's the code I used to move one of them.


    Option Explicit
    Dim Flag As Boolean
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LR As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row

    If Flag = True Then Exit Sub
    If Not Intersect(Target, Range("B2:B100" & LR)) Is Nothing Then
    If Target.Value = "Delivered" Then

    LR = Sheets("DELIVERED").Range("A" & Rows.Count).End(xlUp).Row + 1
    Target.EntireRow.Copy
    Sheets("DELIVERED").Range("A" & LR).PasteSpecial
    Flag = True
    Target.EntireRow.Delete
    End If
    End If
    Application.CutCopyMode = False
    Flag = False
    End Sub

    /close
    Last edited by dojilee; 04-06-2011 at 04:57 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Need help with a macro to move row to another worksheet

    Something like...

    Option Explicit
    Dim Flag As Boolean
    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim LR As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    If Flag = True Then Exit Sub
    If Not Intersect(Target, Range("B2:B100" & LR)) Is Nothing Then
        If Target.Value = "Delivered" Then
            LR = Sheets("DELIVERED").Range("A" & Rows.Count).End(xlUp).Row + 1
            Target.EntireRow.Copy
            Sheets("DELIVERED").Range("A" & LR).PasteSpecial
            Flag = True
            Target.EntireRow.Delete
        ElseIf Target.Value = "Declined" Then
            LR = Sheets("DECLINED").Range("A" & Rows.Count).End(xlUp).Row + 1
            Target.EntireRow.Copy
            Sheets("DECLINED").Range("A" & LR).PasteSpecial
            Flag = True
            Target.EntireRow.Delete
        End If
    End If
    Application.CutCopyMode = False
    Flag = False
    Application.EnableEvents = True
    End Sub
    I've changed the EnableEvents status so the code doesn't call itself while it's running.
    Martin

  3. #3
    Registered User
    Join Date
    04-05-2011
    Location
    US, Ohio
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need help with a macro to move row to another worksheet

    YOU ROCK!! Works awesome. Thank you!

+ 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