2 Attachment(s)
VBA code to delete and replace this month's data
Hello, and thank you in advance for help. I don't do a tremendous amount with VBA and my code isn't quite working.
Context:
Each morning I download an excel file from a third party program and place in a folder (data_bsi_Data). This file is grabbed by the macro in Apriso Build 2022 MASTER file-WC2. Power BI uses this file. We do not want to change this process. There are actually multiple data files that feed into the Master file but only one is used here.
Prior to me dickering with it the Apriso Build 2022 MASTER file would take the day's data and append it to the bottom of its records. But because departments change previous days' data what I want is to remove all of current month's data and replace with new current month's data. I do not want to delete previous month's data (January in this case).
Issue:
My code is appending Feb 01-14th data to end of records. It is not deleting the Feb 01-07
data that currently exists in file. Code is not throwing any errors. I feel it has to do with the code involving the definitions of date variables but I'm not sure.
I've attached dummy files.
Again, thank you. I'm chasing my tail at this point, lol.
What happens on 1st day of month though?
Quote:
Originally Posted by
Bob Phillips
Try replacing your filter with a date filter
Code:
ActiveSheet.Range("A1:G" & LastRow).AutoFilter Field:=5, Criteria1:=currMonth
with
Code:
ActiveSheet.Range("A1:G" & LastRow).AutoFilter Field:=5, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic
On the 1st day of month though it seems like it'd simply paste the data as the the new month (doubling the data essentially) rather than replacing the entire prior month? As example, on Feb 1st when I run data it is data covering Jan 1-Jan31st. This data needs to replace the existing Jan 1- Jan 30 data.