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 change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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