Updating worksheets

joebloggs

New Member
Joined
Dec 7, 2016
Messages
9
Hi All,

I've got a couple of hundred spreadsheets that have a default worksheet listing dates.

Is there a vba, batch file script that will copy a new version of that worksheet to every spreadsheet in a single directory?

The worksheet is named exactly the same "Holidays".

thanks in advance
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I've got a couple of hundred spreadsheets that have a default worksheet listing dates.
Do you really mean "spreadsheets/worksheets", which mean multiple tab in a single Excel workbook, or do you really mean "workbooks", which means multiple files?

If really "worksheets", how can we identify which sheets need updating? Is it ALL of them in the workbook, or just specific ones?
If really "workbooks", are they all in the same folder? Is it every workbook in that folder? If not, how do we identify which ones need updating?

And where is the file that has the new data located? How is it structured?
 
Upvote 0
Hi Joe4,

correct, I'm talking about a single tab within a spreadsheet or as you refer "spreadsheet/worksheet". There are several tabs within each document, but I'm looking to update the data within one specific tab (worksheet) across a lot of spreadsheets all with unique names. The key is that the tab is named exactly the same across all spreadsheets.

the new data can be in the same or different directory, whatever is needed to make the process easy.
 
Upvote 0
the new data can be in the same or different directory, whatever is needed to make the process easy.
Before we can write code to do what you want, you need to laid out the conditions for this, i.e.
- Where should we be looking for these files?
- How do we identify which files we should be opening and updating and which ones we shouldn't?
 
Upvote 0
Look for the files in c:/spreadsheets

update all xlsm files in that directory no matter what they are called. Ie *.xlsm

get the updated data from c:/new/spreadsheets/newdata.xls and tab "holiday".
 
Upvote 0
Try this code. I added lots of documentation so that you can see what is going on.
Code:
Sub MyHolidayReplace()

    Dim srcWB As Workbook
    Dim dstWB As Workbook
    Dim fpath As String
    Dim fname
    
    Application.ScreenUpdating = False
    
'   Open workbook with new data to copy
    Workbooks.Open Filename:="c:/new/spreadsheets/newdata.xls"
    
'   Capture workbook as source workbook
    Set srcWB = ActiveWorkbook
    
'   Activate holiday sheet
    Sheets("Holiday").Activate
    
'   Set file path to look through for files (include extension)
    fpath = "C:\Spreadsheets\*.xlsm"
    
'   Loop through all "xlsm" files in folder
    fname = Dir(fpath)
    While fname <> ""
'       Open workbook
        Workbooks.Open Filename:=fname
'       Capture workbook
        Set dstWB = ActiveWorkbook
'       Go to holiday tab and clear data
        Sheets("Holiday").Activate
        Cells.ClearContents
'       Go to source WB and copy cells
        srcWB.Activate
        Cells.Copy
'       Go to destination workbook and paste
        dstWB.Activate
        Range("A1").Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
'       Save and close destination WB
        dstWB.Save
        dstWB.Close
'       Reset for next file
        fname = Dir
    Wend
        
'   Close source wb
    srcWB.Close
        
    Application.ScreenUpdating = True
    
    MsgBox "Replacement Complete!", vbOKOnly
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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