Copy and paste to last row of a different sheet ignoring filters on target sheet

MNik

New Member
Joined
Aug 30, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
I have a shared file and I am trying to create a macro that will copy a row and paste it to the last row in a different sheet. The issues that I am having is that sometimes the target sheet will have filters applied by other teammates. Is there a way to code the macro to ignore the filters and paste into the last row without having to remove the filters? Here the macro that I currently have.
VBA Code:
Sub OpenOrders_InTransit()

'
'Move row from Open Orders to In Transit
'

Dim RL As Long, CL As Integer
    RL = ActiveCell.Row
    CL = ActiveCell.Column

Application.ScreenUpdating = False

    ActiveCell.Select
        Selection.EntireRow.Select
        Selection.Cut
        Sheets("In Transit").Select
        Range("A" & Rows.Count).End(xlUp).Offset(1).Select
        ActiveSheet.Paste
        ActiveCell.Offset(0, 4).Range("A1").Select
        Selection.Delete Shift:=xlToLeft
        ActiveCell.Offset(0, 14).Range("A1").Select
        Selection.Delete Shift:=xlToLeft
        Range("A" & Rows.Count).End(xlUp).Offset(1).Select
        Sheets("Open Orders").Select
'
' RemoveEmptyRows Macro
'

'
    Columns("A:A").Select
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.EntireRow.Delete
               
  
    Application.ScreenUpdating = True

'
'Return to previous cell
'
    Cells(RL, CL).Select


End Sub

Thanks in advance!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I did not test with filtering but the code in THIS WORKBOOK should do what you need. Also, often there is no need to select everything. Hopefully this gets you started. FYI normally others on the list improve my code, sometimes a lot.

VBA Code:
Sub OpenOrders_InTransit_New()

'   Count of occupied rows in target worksheet (named "In Transit")
    Dim iRowsCount As Long
    
'   Count occupied rows in column A of worksheet named In Transit.
'   Need to place cut values into the next available (empty) row.
    iRowsCount = Worksheets("In Transit").Cells(100000, 1).End(xlUp).Row
    
    Application.ScreenUpdating = False
    
    If ActiveCell.Value Like "Data*" _
     Then
        MsgBox "Cannot move header cells! " & ActiveCell.Address & " was selected."
        Exit Sub
    End If
    
    If ActiveCell.Value = "" _
     Then
        MsgBox "There is nothing in cell " & ActiveCell.Address
        Exit Sub
    End If
    
'   Cut the row in source worksheet (Open Orders) and paste into "next" empty
'   cell in column A in target worksheet (named "In Transit").
    ActiveCell.EntireRow.Cut Worksheets("In Transit").Cells(1, 1).Offset(iRowsCount)
    
    With Worksheets("In Transit").Range("A1").Offset(iRowsCount)

'       Delete cell in column 15 in newly pasted data row.
       .Cells(1, 15).Delete Shift:=xlToLeft

'       Delete cell in column 5 in newly pasted data row.
       .Cells(1, 5).Delete Shift:=xlToLeft

    End With
    
    Worksheets("Open Orders").Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

End Sub
 
Upvote 0
This seems to be much more efficiently written and runs much better than what I currently have. I did test it with filters applied on the target sheet and it writes to the next line numerically which unfortunately overwrites any data in that line.
 
Upvote 0
Without your workbook I'm not sure what the issue is and I do not understand what you mean by "writes to the next line numerically."

Try changing

VBA Code:
ActiveCell.EntireRow.Cut Worksheets("In Transit").Cells(1, 1).Offset(iRowsCount)

to

VBA Code:
ActiveCell.EntireRow.Cut Worksheets("In Transit").Cells(1, 1).Offset(iRowsCount+1)
 
Upvote 0
You might also try clearing the filter before pasting next row

VBA Code:
  If ActiveSheet.AutoFilterMode Then
     ActiveSheet.AutoFilterMode = False
  End If
 
Upvote 0
I was able to get it to work using ActiveSheet.AutoFilter.ShowAllData. Thanks again for your help!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top