Macro to open file if not already in list

shelbinb1532

New Member
Joined
Aug 14, 2017
Messages
8
I have a macro that is designed to open files from a folder (Support Requests) and copy all the relevant data from each to a database file (zzMasterSupportDatabase).
It copies all the information needed onto the next empty row in the database.
Right now it is set to run for all files in Support Requests, and to list the file name in column A. I need to add in an If statement that stops the code from copying a file whose file name is already listed in column A.
 
Filename needs to be a string.
Are the file names in column A of ThisWorkbook.Sheets("Database")
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Apologies, made the wrong correction, that line should be
Code:
If WorksheetFunction.CountIf(SummarySheet.Columns(1), Left(FileName, InStr(FileName, ".") - 1)) = 0 Then
I'm off down the pub now, so I'll check back in tomorrow
 
Upvote 0
Sorry, it's still not skipping existing files. I'm looking for other ways as well but have yet to find one. I'm also open to other solutions if any ideas come to mind.
Thanks for the help.
 
Upvote 0
Ok, having properly looked at the your code try
Code:
If WorksheetFunction.CountIf(SummarySheet.Columns(1), FileName) = 0 Then
 
Upvote 0
Ignore the above & use this
Code:
If WorksheetFunction.CountIf(SummarySheet.Columns(1), FileName) <> 0 Then Exit Do
 
Upvote 0
I'll get it right in the end (honest);)
use
Code:
        If WorksheetFunction.CountIf(SummarySheet.Columns(1), FileName) = 0 Then
& then later in the code add the bit in red
Code:
WorkBk.Close savechanges:=False
        [COLOR=#ff0000]End If[/COLOR]
        ' Use Dir to get the next file name.
        FileName = Dir()
    Loop
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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