Copy data to Database worksheet
The example macro's on this page will copy data from "Sheet1" to a Database sheet with the name "Sheet2". Every time you run one of the macros the cells will be placed below the last row with data or after the last Column with data in the database sheet named "Sheet2" in this example.
Important:
The macro examples use the custom LastRow or LastCol and bIsBookOpen_RB function that you can find in the last section on this page. If you want to use the macro examples in your test workbook do not forget to also copy the functions in a standard module of your workbook.
Before you try the code on this page create a xlsm workbook with two sheets named "Sheet1" and "Sheet2" and in "Sheet1" add some values in "A1:K1" so you can test the code examples. Copy the code from this page inside a Normal Module inside this workbook.
Important:
The macro examples use the custom LastRow or LastCol and bIsBookOpen_RB function that you can find in the last section on this page. If you want to use the macro examples in your test workbook do not forget to also copy the functions in a standard module of your workbook.
Before you try the code on this page create a xlsm workbook with two sheets named "Sheet1" and "Sheet2" and in "Sheet1" add some values in "A1:K1" so you can test the code examples. Copy the code from this page inside a Normal Module inside this workbook.
Copy a range with one area below the last row
Three examples to do this:
1: The first one copies everything
2: The second one uses the value property and will only copy the values.
3: The third one uses PasteSpecial to copy only the values.
See help for more information about the options for PasteSpecial. The PasteSpecial macro's can also be used to transpose the range that you copy, change the last argument too True if you want that.
Note 1: Change the SourceRange and DestSheet in the macros.
Note 2: The three macros in this section use the function LastRow.
1: The first one copies everything
2: The second one uses the value property and will only copy the values.
3: The third one uses PasteSpecial to copy only the values.
See help for more information about the options for PasteSpecial. The PasteSpecial macro's can also be used to transpose the range that you copy, change the last argument too True if you want that.
Note 1: Change the SourceRange and DestSheet in the macros.
Note 2: The three macros in this section use the function LastRow.
Note: in the last macro you can also use xlPasteValuesAndNumberFormats so it also copy the numberformats to the database sheet.
Copy a range with more then one area below last row
Tip: Use a row below your data with links to cells you want (=C3 in A50, =G15 in B50, …..).
You can hide this row if you want and copy a range like A50:Z50 for example with one of the one area examples above.
Here are two examples that use the Value property to copy a range with more then one area
Note 1: Change the SourceRange and DestSheet in the macros.
Note 2: The two examples in this section use the function LastRow.
You can hide this row if you want and copy a range like A50:Z50 for example with one of the one area examples above.
Here are two examples that use the Value property to copy a range with more then one area
Note 1: Change the SourceRange and DestSheet in the macros.
Note 2: The two examples in this section use the function LastRow.
Copy a range with one area after the last column
Note 1: Change the SourceRange and DestSheet in the macros.
Note 2: The example in this section use the function LastCol.
Note 2: The example in this section use the function LastCol.
What if the Database sheet is in another workbook
Here is a example that uses the Value property to copy a range to another file
Note 1: Change the SourceRange and DestSheet and path/file name in the macros.
Note 2: The example in this section use the functions LastRow and bIsBookOpen_RB.
The macro will open the database workbook Backup.xlsx if it is not open (It uses the function bIsBookOpen_RB to check if the workbook is open or not). This workbook must be in the same folder as the workbook with the code in this example.
Note 1: Change the SourceRange and DestSheet and path/file name in the macros.
Note 2: The example in this section use the functions LastRow and bIsBookOpen_RB.
The macro will open the database workbook Backup.xlsx if it is not open (It uses the function bIsBookOpen_RB to check if the workbook is open or not). This workbook must be in the same folder as the workbook with the code in this example.