Whittlebury
New Member
- Joined
- Apr 18, 2023
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I'm trying to copy the 1st 3 columns of a filtered table to the bottom of another table on a different worksheet but only if any rows have been found.
The following works ok (but happy to know any better solutions) but I need to check if any filtered rows are found as otherwise it copies the entire table.
Many thanks
The following works ok (but happy to know any better solutions) but I need to check if any filtered rows are found as otherwise it copies the entire table.
Many thanks
VBA Code:
Sub CopyNewFiles()
'
' CopyNewFiles Macro
'
'
Dim wb As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lr As Variant
Dim lo As ListObject
Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("link-report")
Set ws2 = wb.Worksheets("PDF Xrefs")
Application.ScreenUpdating = False
' Refresh the csv import table
'wb.RefreshAll
' Filter any NEW pdfs
ws1.ListObjects("link_report").Range.AutoFilter Field:=5, Criteria1:="NEW"
'If the filtered table contains any rows Then [B]<< this condition is the bit I'm struggling with[/B]
'Add empty row to the main table
Set lr = ws2.ListObjects("PDF_Xref").ListRows.Add
'Copy the 1st 3 columns of the filtered table
ws1.ListObjects("link_report").ListColumns(1).DataBodyRange.Resize(, 3).Copy
'Paste the input into the main table
lr.Range.PasteSpecial xlPasteValues
'End If
'De-select the input data
Application.CutCopyMode = False
End Sub