• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Compare 2 excel files and add a checking if a file has run before

zardi

New Member
Hi all,

I currently have 1 excel with 2 tables, 1 is datatable and 1 is instruction table.
The instruction table is used to update the datatable daily.
(I have attached as Old Datatable.xlsm)

But now I need to do something abit complicated.
First of all, instead of 1 excel, I want to split into 2 excel files in the same directory.
First is Datatable.xlsm which holdes the master records
Second is InstructionYYYYMMDD.xlsm which holds daily instructions to be updated. (it will be a different file each day)

Can anyone teach me how to:
1) in the Datatable.xlsm, when I run the macro, it will load InstructionYYYYMMDD.xlsm (where YYYYMMDD equals to today's date), and then run my original codes to update the Datatable accordingly.
2) add a checking, if a file has been loaded already, display a message "file already loaded before" and stop.
For this, I am thinking in the Datatable.xlsm, add a sheet call Loaded. This will save down all the YYYYMMDD that has loaded already and use this as a comparison. Is this feasible?

Thanks!
 

Attachments

  • Old Datatable.xlsm
    19.1 KB · Views: 0
Last edited:
Added sample files for the new approach. thanks.
 

Attachments

  • Datatable.xlsm
    9.2 KB · Views: 3
  • instruction20160816.xlsm
    8.8 KB · Views: 4
For 1) i changed it to below
1) when run the macro, I will popup a dialog box using
Code:
  OpenDaily = Application.GetOpenFilename(FileFilter:="All files (*.*), *.*", Title:="Please open the Daily File")


  If OpenDaily <> False Then

  Workbooks.Open Filename:=OpenDaily
  
  End If
and then run my original codes to update the Datatable accordingly.
 
I guess trying to focus on 1) first, right now i changed it to
Code:
  Set rTable = ThisWorkbook.Sheets("MasterTable").Range("A1").CurrentRegion
  vFile = Application.GetOpenFilename("Excel files (*.xls*), *.xls*", , "Please select an instruction file")
  If TypeName(vFile) = "Boolean" Then Exit Sub
  Set WB = Workbooks.Open(vFile, ReadOnly:=True)

But I still don't know how to adjust the codes so that it checks the new opened file, any tips? Thanks
 
Back
Top