Macro for making a backup of multiple ranges

Hoeye

New Member
Joined
Apr 7, 2009
Messages
7
Dear experts,

I'm developing sort of a year-planner/invoice-maker. This is a work in progress, but it's working and as of 1-1-2010 it's in use! My collegue filled the year.

Now I'm working on the workbook. Changing this, and that, modifying macros. Now I'm looking for this:

I want my collegue to be able to press a backup button > this backs up about 20 ranges on every one of 15 worksheets. A file must be created "backup -date-<DATE>.xlsx" or something similar. Backing up the whole workbook is easy, but I don't know how to back up only the needed ranges.

Now I take this backup file, and press a restore (or import) button, and the macro takes this backupfile and imports the data.

I searched the forum, googled the internet, but I haven't seen a solution.

Can someone point me in the right direction?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This is the fastest and easiest way to back up large ranges that I know of. The example backs up a range named "MyBackUpRange" and then clears the contents of the same. It then restores the range. Name a large range using the name above to test...

Code:
Sub Example()
    BackUpRange "MyBackUpRange"
    Range("MyBackUpRange").ClearContents
    MsgBox "Contents Cleared.  Will now restore."
    RestoreRange "MyBackUpRange"
End Sub

Sub BackUpRange(SourceName As String)
    Dim Data, FileNum As Integer

    Data = Range(SourceName)
    FileNum = FreeFile
    Open ThisWorkbook.Path & "\" & SourceName & ".dat" For Binary As #FileNum
        Put #FileNum, 1, Data
    Close #FileNum
End Sub

Sub RestoreRange(TargetName As String)
    Dim Data, FileNum As Integer

    FileNum = FreeFile
    Open ThisWorkbook.Path & "\" & TargetName & ".dat" For Binary As #FileNum
        Get #FileNum, 1, Data
    Close #FileNum
    Range(TargetName) = Data
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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