VBA: update backup file when running macro

Newbie_92

New Member
Joined
Aug 11, 2022
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
Hi,

Im having a code below for copying data from workbook to another. The Master file is stored in SharePoint so I would like to have backup file as well to be stored in server.
Any ideas how to modify the code so that it updates the backup file also each time the macro is running?

VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, i As Integer, ActSht As Worksheet

    Set ActSht = ActiveSheet
    LastRow = ActSht.Range("A" & Rows.Count).End(xlUp).Row
 
    Workbooks.Open Filename:="path...."
    Worksheets("Master").Unprotect Password:="password"

    For i = 2 To LastRow

        If ActSht.Cells(i, 15).Value = "Yes" Then

        Range(ActSht.Cells(i, 1), ActSht.Cells(i, 14)).Copy Worksheets("Master").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
          
        End If
    Next i
 
              
    Worksheets("Master").Protect Password:="password"
    ActiveWorkbook.Save
    ActiveWorkbook.Close
 
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Prior to saving and closing your workbook...

VBA Code:
ActiveWorkbook.SaveCopyAs "c:\path_to_backup_folder\" & ActiveWorkbook.Name

By the way, since it looks like you're not making any changes to your master workbook. If this is the case, you can simply close the workbook without saving as follows...

VBA Code:
ActiveWorkbook.Close SaveChanges:=False

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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