exceloffice365

Delete entry from the spreadsheet and move the particular data field to other spreadsheet


I have 2 spreasheets in excel file where I enter the daily objects to be completed in spreadsheet 1 and master data in spreadsheet 2 ( where the the objects which are completed are stored )

As of now, I manually delete the entries from spreadsheet 1 and save those entries in master data i.e. spreadsheet 2 ( cut and paste )

Is there any way so that I can automate this process if I add a new column and update "Completed" and then the entry gets removed from spreadsheet 1 and moved to spreadsheet 2.

I have attached the desired output screenshots below:

Sheet 1 ( daily objects to be completed ): enter image description here

Master Data ( where the completed objects are saved and then deleted from spreadsheet 1 )

enter image description here

After this, the updated Sheet 1 should look like this: enter image description here

Thank you everyone in advance.


Solution

  • This code moves the complete rows marked as Completed from Sheet1 to Master Sheet. Does the task for reversed rows to avoid numbering conflicts when deletion occurs.

    Sub move_rows()
    
    Dim sourcesheet As Worksheet, targetsheet As Worksheet
    Set sourcesheet = Worksheets("Sheet1")
    Set targetsheet = Worksheets("Master Sheet")
    
    lastrow = sourcesheet.Range("A1").End(xlDown).Row
    targetrow = targetsheet.Range("A1").End(xlDown).Row + 1
    If targetrow = 1048577 Then targetrow = 1
    For i = lastrow To 1 Step -1
      If sourcesheet.Cells(i, 3) = "Completed" Then
        sourcesheet.Rows(i).Copy targetsheet.Rows(targetrow)
        targetsheet.Rows(targetrow).Insert
        sourcesheet.Rows(i).Delete
      End If
      
    Next i
    targetsheet.Rows(targetrow).Delete
    End Sub