Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49895

Move entire row to other sheet without inserting new rows

$
0
0
hi,

I have searched the below code in this forum. It work but not that perfect. After all rows with "y" on column "J" are moved, it keeps inserting new rows when user clicks on the button (by mistake). I tried to search on the remedy but failed. kindly help.



Code:

Sub MoveMatched_GL()
Dim lr As Long
Application.ScreenUpdating = False

    Sheets("GL ENTRIES").Unprotect "classA"
    Range("A3").EntireRow.Insert Shift:=xlDown
    lr = Sheets("GL ENTRIES").Cells(Rows.Count, "J").End(xlUp).Row
    If lr < 3 Then Exit Sub
    LR1 = Sheets("GL-Cleared").Cells(Rows.Count, "A").End(xlUp).Row + 1
        With Sheets("GL ENTRIES").Range("J3:J" & lr)
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:="Y", _
            Operator:=xlOr, Criteria2:="y"
            Sheets("GL-Cleared").Unprotect "classA"
            .SpecialCells(xlCellTypeVisible).EntireRow.Copy Destination:=Sheets("GL-Cleared").Range("A" & LR1)
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
   
            Sheets("GL-Cleared").Select
            Cells.Select
            Selection.Locked = True
            Selection.FormulaHidden = False
            Sheets("GL-Cleared").Protect "classA"
   
            End With
            Sheets("GL ENTRIES").Select
            Range("A1:J1").Select
            Selection.Locked = True
            Selection.FormulaHidden = True
            Rows("2:2").AutoFilter
            ActiveSheet.Protect "classA", DrawingObjects:=False, Contents:=True, Scenarios:= _
            False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
            AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
            :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
            AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
            AllowUsingPivotTables:=True
            Range("J3").Select
           
   

End Sub


Viewing all articles
Browse latest Browse all 49895

Trending Articles