rodrigo_m_almeida
New Member
- Joined
- Jan 13, 2022
- Messages
- 42
- Office Version
- 2021
- Platform
- Windows
Could anyone help ?
How can I do this...
Trying this way
Problem with advancedfilter !
How can I do this...
Trying this way
Problem with advancedfilter !
VBA Code:
Public Sub SEARCH()
' Optimize
Application.Visible = False: Application.ScreenUpdating = False: Application.DisplayAlerts = False
' Declare Variables
Dim xPathName, xFileName As String, xOldWB, xNewWB As Workbook
' Browse Folder
Set FileDialog = Application.FileDialog(msoFileDialogFolderPicker)
FileDialog.Title = "Select Folder :"
If FileDialog.Show = -1 Then xPathName = FileDialog.SelectedItems(1) Else Exit Sub
If Right(xPathName, 1) <> "\" Then xPathName = xPathName + "\"
' Open File 02
Workbooks.Add
Set xNewWB = ActiveWorkbook
' Search File
xFileName = Dir(xPathName & "FINAL*.xlsx")
' Open File 01
Do While xFileName <> ""
Workbooks.Open Filename:=xPathName & xFileName
Set xOldWB = ActiveWorkbook
' Copy And Paste (Unique) for Other Workbook / >>> ERROR 1004 <<<
xOldWB.Sheets(1).Columns("A:D").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=xNewWB.Sheets(1).Columns("A:D"), Unique:=True
' Save File 01
' Close File 01
xOldWB.Close
' Next File
xFileName = Dir
Loop
' Save File 02
xNewWB.SaveAs Filename:=xPathName & "ABC123", FileFormat:=xlWorkbookDefault
' Close File 02
xNewWB.Close
' Optimize
Application.Visible = True: Application.ScreenUpdating = True: Application.DisplayAlerts = True
Last edited: