+ Reply to Thread
Results 1 to 3 of 3

Auto Move Rows macro is deleting needed data

Hybrid View

jessica.betando Auto Move Rows macro is... 03-26-2013, 09:06 PM
rylo Re: Auto Move Rows macro is... 03-26-2013, 09:12 PM
jessica.betando Re: Auto Move Rows macro is... 03-26-2013, 09:20 PM
  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Auto Move Rows macro is deleting needed data

    Greetings,

    This is my first time posting. I originally joined due to some great help I received here in recording a macro for my RACI matrix (original post here), which moved each row in my table once that project's status was "complete" by deleting it and placing in it the first empty row in Sheet2. I modified the macro to fit my purposes, but now instead of pasting the row in the first empty space, it pastes it in the same row each time, deleting the last completed project. If someone is willing to tell me what I'm doing wrong and how to fix what I messed up in the code, I would be very grateful. I am very much a novice at this--this is only the second time I've ever used VBA! I've included both my file and my code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim nextrow As Long, i As Long
        
        nextrow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row + 2
        
        If Target.Cells.Count > 1 Then Exit Sub
        
        Application.ScreenUpdating = False
        If Not Intersect(Target, Range("P2:P" & Cells(Rows.Count, "P").End(xlUp).Row)) Is Nothing Then
            i = Target.Row
            If Target.Value = "Complete" Then
                Range(Cells(i, "A"), Cells(i, "I")).Copy Sheet2.Range("A" & nextrow)
                Range("A" & Target.Row).EntireRow.Delete
            End If
        End If
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    
    End Sub
    JessicaB Project List.xlsm

    Thank you very much!
    Jessica
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Auto Move Rows macro is deleting needed data

    Hi

    Your variable nextrow is being filled based on column A. However, you don't have any data in column A so it will keep going to the same next row. Try basing it on column B and see how that goes.

    nextrow = Sheet2.Cells(Rows.Count, "B").End(xlUp).Row + 2
    rylo

  3. #3
    Registered User
    Join Date
    03-25-2013
    Location
    California, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Auto Move Rows macro is deleting needed data

    Aha! That makes sense! Your correction worked perfectly. Thank you, rylo!

+ 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