Note: This is meant as a quick-and-dirty guide to getting up and running with a Google Sheets macro. I don't claim that this is enough to keep things well organized.
- Head to
script.google.com
- Click "New Project"
- Click "Untitled project" at the top and give your project a descriptive name
-
Modify the following to suit your needs and paste it into the editor:
function copyData() { // This will grab the currently active spreadsheet, which will be the one // you're looking at when you run the script. var ss = SpreadsheetApp.getActive(); // This is the source sheet/tab. Change Sheet1 to the name of the source // sheet. var sourceSheet = ss.getSheetByName('Sheet1'); // This is the destination sheet/tab. Change Sheet2 to the name of the destination sheet. var destSheet = ss.getSheetByName('Sheet2'); // This is the range that you'll be copying from the source. Change A:A // to be whatever the valid A1 notation range should be. var sourceRange = sourceSheet.getRange("A:A"); // This is the range that you'll be copying from the source. Change A:A // to be whatever the valid A1 notation range should be. var destRange = destSheet.getRange("A:A"); // Do the actual copying sourceRange.copyTo(destRange, SpreadsheetApp.CopyPasteType.PASTE_NORMAL); }
Hit Ctrl+s to save
Open your spreadsheet
Click Tools -> Macros -> Import
Click "Add Function"
Close the dialog window
You can now use the function you created by clicking Tools -> Macros -> copyData (or whatever you renamed the function to).
There are a lot of other tricks you can use, like creating a trigger to run the function when the sheet changes, setting a keyboard shortcut, etc. but those are outside the scope of this post.
Top comments (1)
Perfect, just what I needed! Thank you.
Cheers,
Meelad
Apipheny