+ Reply to Thread
Results 1 to 7 of 7

Clear row contents and copy row contents.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    244

    Clear row contents and copy row contents.

    I am wondering if two seperate macros are possible that

    1>Copy the entire Row if the Column C Contains "Completed" in a new sheet called "Done"
    I mean will append the new rows if the macro is run again. Without duplicating and update if already existed. Column B contains unique serial number.

    another macro when run

    2>That will clear the contains from Row C to M if the Column C Contains "Completed" in the entire sheet.

    Any help is much appreciated.
    Thanks in advance,

  2. #2
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Clear row contents and copy row contents.

    could you post an example workbook with some dummy data to show what exactly you need

  3. #3
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    244

    Re: Clear row contents and copy row contents.

    I have uploaded as required.
    Thanks in advnce.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Clear row contents and copy row contents.

    Hi

    No need for 2 macros, it can all be completed in one.
    See attached workbook

    
    Sub MoveCompletedData()
        Dim lr1 As Long, lr2 As Long
        Dim ws1 As Worksheet, ws2 As Worksheet
    
        Set ws1 = Sheets("All Data")
        Set ws2 = Sheets("Done")
        Application.ScreenUpdating = False
        lr1 = ws1.Cells(Rows.Count, 1).End(xlUp).Row
        lr2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row + 1
    
        ws1.Range("$A$1:$E$1").AutoFilter Field:=3, Criteria1:="Completed"
    
        ws1.Range("A2:E" & lr1).SpecialCells(xlCellTypeVisible).Copy ws2.Range("A" & lr2)
    
        Application.CutCopyMode = False
        Range("A2:E" & lr1).SpecialCells(xlCellTypeVisible).ClearContents
        ws1.Range("$A$1:$E$19").AutoFilter Field:=3
        ws1.AutoFilter.Sort.SortFields.Clear
        ws1.AutoFilter.Sort.SortFields.Add Key:=Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending
        With ws1.AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
             .Apply
        End With
        ws1.Range("A2").Select
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  5. #5
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    244

    Re: Clear row contents and copy row contents.

    It's working .
    But when I am clicking the button. it's creating a filter. Which I dont need.

    The data are moving perfectly,But the button is still pressed once clicked.

    When clicked again giving error and hiding the rows in All Data.I mean if there is no Record to update it is giving the error.

    Also it will be great If there can be a button to copy the "going " entries in a new sheet Called "Progress". So that I can see the entries which is still on going.

    That's all.

    Thanks for everything Roger.

  6. #6
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Clear row contents and copy row contents.

    Hi

    use this modified code
    
    Sub MoveCompletedData()
        Dim lr1 As Long, lr2 As Long
        Dim ws1 As Worksheet, ws2 As Worksheet
    
        Set ws1 = Sheets("All Data")
        Set ws2 = Sheets("Done")
         If WorksheetFunction.CountIf(ws1.Range("C:C"), "Completed") = 0 Then
        
        MsgBox "No Complteded entries to move"
        Exit Sub
        Else
        Application.ScreenUpdating = False
        lr1 = ws1.Cells(Rows.Count, 1).End(xlUp).Row
        lr2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row + 1
       
        
        ws1.Range("$A$1:$E$1").AutoFilter Field:=3, Criteria1:="Completed"
    
        ws1.Range("A2:E" & lr1).SpecialCells(xlCellTypeVisible).Copy ws2.Range("A" & lr2)
    
        Application.CutCopyMode = False
        Range("A2:E" & lr1).SpecialCells(xlCellTypeVisible).ClearContents
        ws1.Range("$A$1:$E$1").AutoFilter Field:=3
        ws1.AutoFilter.Sort.SortFields.Clear
        ws1.AutoFilter.Sort.SortFields.Add Key:=Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending
        With ws1.AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
             .Apply
        End With
        ws1.Range("A2").Select
        End If
        ws1.Range("A1:E1").AutoFilter
        Application.ScreenUpdating = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    02-07-2011
    Location
    Bhutan
    MS-Off Ver
    Excel 2007
    Posts
    244

    Re: Clear row contents and copy row contents.

    Awesome Bro !
    It's perfect. 5 Star !!!

+ 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