You are on page 1of 7

Boost

Productivity With These Excellent Goo


Scripts

Did you know that the suite of products on Google Drive (https://drive.google.com), especially Google

extended by custom scripts? These scripts can dramatically improve your productivity (http://www.ma

drive-which-is-best-for-office-productivity/) while using Google Spreadsheet, and its relatively easy to


own!

If you use a spreadsheet application to crunch data, then custom scripts could be the master key. Sta
Spreadsheet scripts and make use of your data in new ways.

How To Use Scripts

Let's go
http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

Before you begin drooling over the following Google Spreadsheet scripts, its important to know how

1. To add a script, youll need to log into Google Drive, go to a spreadsheet, choose Tools Script E

2. Copy and paste the script code, and then click on Save.

3. To run the script, just go to Tools Script Manager and choose the function you want. The nam
name in the first line of the script, i.e. function removeDuplicates() results in the script being called

For all of you scripting and programming nerds, the scripts are written in JavaScript (http://www.make

works/). Google has various resources that describe the API (https://developers.google.com/apps-scr

you need to catch up on your JavaScript, there are plenty of free JavaScript resources (http://www.ma
resources-for-learning-javascript-by-doing/) you can use.

http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

Remove Duplicates

If youre working with a large spreadsheet that may have repeat information, it may be advantageous t

(depending on the context of your work). This way, you have a perfect dataset to work with that won
The script code for this is the following:
function removeDuplicates() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var newData = new Array();
for(i in data){
var row = data[i];
var duplicate = false;
for(j in newData){
if(row.join() == newData[j].join()){
duplicate = true;
}
}
if(!duplicate){
newData.push(row);
}
}
sheet.clearContents();
http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);


}

With a bit of research, I am sure that this script can also be tweaked to count the number of times an
entries first and then delete the duplicates.

Send Email From Spreadsheet

Did you know that you can also send emails from a spreadsheet? Absolutely! For this specific script, y

message body, but the subject line is fixed. You can change it in the script code, or you can modify th

between the recipient and the message body for a subject. Then, just modify the number of items to b
script code for this is:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
// Fetch values for each row in the Range.
http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

var data = dataRange.getValues();


for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var subject = "Sending emails from a Spreadsheet";
MailApp.sendEmail(emailAddress, subject, message);
}
}

Expanded Conditional Formatting

One of the most useful features of spreadsheets is conditional formatting a custom rule on a per-ce

(such as fill color) depending on the content of the cell. It works well, but it is also limited for single cell
formatting to an entire row, for example, then youll need to use a script.

This here is an example script that should do the job. This script sets the row color depending on the
function setRowColors() {
http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

var range = SpreadsheetApp.getActiveSheet().getDataRange();


var statusColumnOffset = getStatusColumnOffset();
for (var i = range.getRow(); i < range.getLastRow(); i++) {
rowRange = range.offset(i, 0, 1);
status = rowRange.offset(0, statusColumnOffset).getValue();
if (status == 'Completed') {
rowRange.setBackgroundColor("#99CC99");
} else if (status == 'In Progress') {
rowRange.setBackgroundColor("#FFDD88");
} else if (status == 'Not Started') {
rowRange.setBackgroundColor("#CC6666");
}
}
}
//Returns the offset value of the column titled "Status"
//(eg, if the 7th column is labeled "Status", this function returns 6)
function getStatusColumnOffset() {
lastColumn = SpreadsheetApp.getActiveSheet().getLastColumn();
var range = SpreadsheetApp.getActiveSheet().getRange(1,1,1,lastColumn);
for (var i = 0; i < range.getLastColumn(); i++) {
if (range.offset(0, i, 1, 1).getValue() == "Status") {
return i;
}
}
}

However, note that the script is hard-coded, so youll need to change the test values (the content in th
maybe even add or remove cases as necessary for your spreadsheet.

Conclusion

As you can see, scripts can be extremely useful in Google Spreadsheet. They tend to be very specializ
http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

plan on using one that doesnt come from the Script Gallery, theres a high chance that youll need to
However, Google has plenty of resources and tutorials (https://developers.google.com/apps-script/)
have everything you need to do the job.

That being said, dont be afraid to check out the Script Gallery found under the Tools menu. There a

do a lot for your day to day productivity. Ryan also showed us some amazing Google Spreadsheet fun

(http://www.makeuseof.com/tag/useful-google-spreadsheet-functions/). Using Google Forms, Googl

(http://www.makeuseof.com/tag/10-advanced-tips-tricks-for-google-forms/) is a power-task worth le

Sign up for more tips and awesome articles

E-mail

http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/

Created with PrintWhatYouLike.com

You might also like