Hi all,
I have a problem with my VBA code below. The point is in the assigned macro in the below xlsm the user to get filtered data from a source xlsx based on today's date, once it press it.
The source workbook will be updated everyday thus the range will be for all G column.
I want to open in hidden mode the source --> filtering the results of column G (today's date) and pasting the results (if found) in the destination xlsm A2 : ... .
The errors that I get:
Any help would be much appreciated
I have a problem with my VBA code below. The point is in the assigned macro in the below xlsm the user to get filtered data from a source xlsx based on today's date, once it press it.
The source workbook will be updated everyday thus the range will be for all G column.
I want to open in hidden mode the source --> filtering the results of column G (today's date) and pasting the results (if found) in the destination xlsm A2 : ... .
VBA Code:
Sub CopyFilterPaste()
'Declare variables for the source and destination workbook
Dim sourceWB As Workbook, destWB As Workbook
'Open the source workbook in hidden mode
Set sourceWB = Workbooks.Open("\\argsrv\Users-Data\sales\iq2857\deliveries demo\Deliveries 2022.xlsx", UpdateLinks:=0, ReadOnly:=True, Visible:=False)
'Open the destination workbook
Set destWB = Workbooks.Open("\\argsrv\Users-Data\sales\iq2857\deliveries demo\Test Deliveries.xlsm")
'Filter the source workbook based on today's date in column G
With sourceWB.Sheets("Deliveries")
.Range("A:G").AutoFilter Field:=7, Criteria1:="=" & Format(Date, "DD/MM/YYYY")
End With
'Determine if there are any visible cells after the filter is applied
If sourceWB.Sheets("Deliveries").Range("A1:G2814").SpecialCells(xlCellTypeVisible).Count = 1 Then
MsgBox "No deliveries for today", vbOKOnly
sourceWB.Close SaveChanges:=False
destWB.Close SaveChanges:=False
Exit Sub
End If
'Copy the filtered data
sourceWB.Sheets("Deliveries").Range("A2:G100").SpecialCells(xlCellTypeVisible).Copy
'Paste the filtered data into the destination workbook
destWB.Sheets("Today's Deliveries").Range("A2").PasteSpecial xlPasteValues
'Close the source workbook
sourceWB.Close SaveChanges:=False
'Close the destination workbook
destWB.Close SaveChanges:=True
End Sub
The errors that I get:
Any help would be much appreciated