Multiple Cell Data and Formula Reference With Find and Replace – Google Sheets

One of my biggest regrets when I first got started with Google Sheets and spreadsheets in general, was not taking full advantage of Find and Replace.

Find and Replace is the penicillin of the the Spreadsheet world. It can rapidly cure all sorts or issue with a simple set of commands. It is seriously amazing stuff.

Yeah! Yeah! We all know about Find and Replace.

I know! I thought so too, but then I started to really use and identify how I could use it to quickly:

  • Change template sheets.
  • Fix bulk errors in formulas.
  • Change parts of cells.
  • Replace values in the whole spreadsheet, one sheet or a selected range.

Before we get started, you need to know the short cut for the Find and Replace tool. This will come in handy in all sorts of programs and apps.

  • PC – Ctrl + H
  • Mac – CMD (⌘) + H

I’m going to go ahead and continue the examples using PC, because, you know, Mac.

Continue reading “Multiple Cell Data and Formula Reference With Find and Replace – Google Sheets”

5 Easy Shortcuts That Will Save you Heaps of Time – Google Sheets

It’s time to get evangelical peep! Release yourself from the yolk of the menu bar and it’s insidious demands on you coordination and time!

Break free from the right click menu! For is it not anything more than a proxy menu bar?! A veritable wolf in sheep’s clothing with no other design but to bring you back to the fold of the menu-using, mouth-drooling reprobates  who stand in the way of efficient progress! Can I get an Amen! I said, can I get an Amen!

No? Fair enough…

Let’s just get on with it then, shall we? After all, this is about efficiency, right?

Here are the 5 main shortcuts that I use in Google Sheets each and every day to save me a tonne of time. I’m going to give you a bit more than just the Keyboard Shortcut, I’m going to demonstrate how I use it with some clear examples.

Continue reading “5 Easy Shortcuts That Will Save you Heaps of Time – Google Sheets”

Google Sheets – How to Separate the First Name from a Full Name Cell

left, right, find, length

Every academic quarter I receive a list of students by their full name in one cell that I need to split into a cell for the first name and then a cell for the middle and last names combined. 

This fairly simple process can be achieved with the Google Sheets formulas left, right and find. 

If you are in a hurry, here are the formulas below: 

First Names

To get the first name we do the following: 

=LEFT(A2,FIND(” “,A2))

Where ‘A2’ is the cell that we have our full name in – in our case Vasco Nunez de Balboa.

When you have multiple formulas in a cell it’s often best to go from the inside out. So let’s first look at what FIND does. 

FIND looks inside the cell for the first value that we want to search for. For us, it’s an empty space, ” “. Find then returns the numerical position of that found item.  To do this FIND takes two arguments: 

=FIND(the item we are searching for, the cell or string the item is in)

For example if we are searching for the location of the space in
 Vasco Nunez de Balboa  which is in cell A2,  we would do the following:

=FIND(” “,A2)

Which would give the result: 6

There are five letters in the first name Vasco the the space would be position 6. 

Now that we have the position  of the space, lest just grab everything in the cell to the left of that space. We do this with LEFT

LEFT also take two values. The first is cell location and the second is the number characters we want to take from the left hand side. 

LEFT(cell location, number of characters from the left)

Now that we know the first space is character 6, the formula would look like this:

LEFT(A2,6)

We then replace the 6 with our FIND formula and we are good to go.

Continue reading “Google Sheets – How to Separate the First Name from a Full Name Cell”

Google Apps Script – How to Get the Sheet Name and Spreadsheet Name and add to a Cell on Google Sheets with a Custom Function

Google Apps Script, Custom Functions

Boy, are these titles getting longer. 

But that’s pretty much the gist of it. In this post we will look at creating a Google Apps Script Custom Function that allows you to do Three thing in Google Sheets: 

  1. Get the current sheet name.  That’s the same sheet name as the cell you are working in.
  2. Get all the sheet names. A full list of all the sheet names. 
  3. Get the name of the Spreadsheet file. 
Get Sheet Names and Spreadsheet Names Only - Google Apps Script

The above picture is pretty self explanatory. If you type in:

=SHEETNAME(#)

Where “#”  is a number 0, 1 or 2 you will get the results displayed in the picture. Any other number will display an error. 

How do I add this amazing Custom Function To my Google Sheet?

First copy the code below. Then go to <Tools>>Script Editor> This will open the Google Apps Script Editor. 

Next Rename the Project to whatever you want. I usually name it the same as my sheet. 

Next delete all the code in the Code.gs file and paste in our code. 

<File><Save> in the Project and then return to your spreadsheet and give it a try. 

The Code

You can learn more about how to build a Custom Function by following my tutorial:

Application

SHEETNAME  can be used in conjunction with other built-in functions in Google Sheets. 

It can be used in part, or as a whole as a naming or titling tool. For example, imagine our Spreadsheet file title is 2018-2019 Top Stocks and our Sheet Name for the current tab is Tech. Perhaps when we duplicate this file each year we just want the title inside our Tech Sheet to automatically update:

Which would generate:

2018-2019 Top Stocks-Tech

Another options might be a referencing tool to quickly create formulas in other sheets. Take a look a this example: 

Get SheetName Example Google Apps Script

Conclusion

So, I would be interested to see what you use this custom function for, if you found it useful. 

Have you done anything interesting with the code? I would love to see how you have advanced the Google Custom Function.

~Yagi

Google Apps Script – Copy Selected Columns in One Sheet and Add Them To The Bottom of Different Selected Columns in Another

I recently had a legend (a.k.a reader) ask about how to copy selected columns from one sheet and append them to the bottom of different selected columns in another sheet. 

To me, this seemed like a pretty common task that one might face, so in response I decided to create a template function to easily do this and reuse on the same project or in other projects. 

But first, let’s take a look a the problem a bit more. 

We want:

  1. the freedom to select any number of columns from one sheet.
  2. to select the same number of different columns from the sheet we want to paste to.
  3. to paste to the bottom (append) the receiving sheet.
  4. to take into account varying header row heights.
  5. to have a “Completed” or “Copied” column in our origin sheet so that we don’t continue to paste all the data instead of simply what has been updated.
  6. have the data with formulas that we only want to paste the values for.

The Example

Let’s say we have a sheet that is updated regularly and we want to be able to paste data from columns A,B and C of this source sheet and append it to columns C,E and A of the destination Sheet. 

  • Copy Sheet 1 Col A -> Append Sheet 2 Col C
  • Copy Sheet 1 Col B -> Append Sheet 2 Col E
  • Copy Sheet 1 Col C -> Append Sheet 2 Col A

Take a look at our two Google Sheets 

SourceSheet - Google Sheets
DestinationSheet - Google Sheets

You can see in the Source Sheet (Sheet1) that we have 3 data columns and one column market To Copy. The To Copy column will be updated with “Copied” once the code is run successfully.

In the Destination Sheet (Sheet2) you can see that we already have some data there. We don’t want to overwrite it. We simply want to append our data to the bottom of it. 

Continue reading “Google Apps Script – Copy Selected Columns in One Sheet and Add Them To The Bottom of Different Selected Columns in Another”

Google Apps Script – How to Change the File Name of Non-Native Files like MS Word Docs, PDF’s and Excel files.

Google Apps Script, DriveApp

I had an unexpected need to change some non-native file names – in my case, MS Word docs – to something else to appease my masters. Being the resident Igor, I delighted in the task. 

The Problem

I had a folder of MS Word documents on my Google Drive that needed to all be renamed. They all needed the same name with an index number to distinguish that they were different files. 

There were, however other file types in the folder. 

The problem with non-native files in Google Drive is that it’s a little tricky to find their ID. Besides I just wanted to change ALL files that were MS Word in the folder. 

What I would need to do is search for all files inside my selected folder that are of MS Word type and rename them with the same name but with a counter at the end. For example:

Old File NameNew File Name
boring.doccranberrySauce.doc
sad.doc cranberrySauce1.doc
yawn.doc cranberrySauce2.doc
Continue reading “Google Apps Script – How to Change the File Name of Non-Native Files like MS Word Docs, PDF’s and Excel files.”

Instagram Diaries 3 – Day One and My First Pics

If  you missed Part 1 of the Instagram Diaries – how it all began – you can click here!

The cat’s out of the bag! Mrs Yagi got wind of what I was doing and read my first article on the Instagram Diaries.  So much for that secret-not secret rant in the last post. Ha!

Day One of posting was a challenging day. I had some choices to make. Do I start uploading photos of my most recent vacation or do I start at the very beginning of the photos from my phone all the way back in 2016?

Those first photos happened to be taken on a trip to Egypt and there were trips to Australia, Jordan, Sri Lanka, Thailand and Romania that I could add as well ( Oh Yagi! You place dropping hussy!). I like the idea of starting from the beginning for two reasons:

  1. I wouldn’t have to scramble for pictures now. Instead I could pick the best from what I had and slowly release them 1 to 3 a day.
  2. When else am I going to look at these photos? I reckon I am like almost everyone else and take photos for the sake of taking photos and never really go back on a trip down memory lane. 

First Pic Away

Awh yeah! Cool! I remember that little guesthouse with perfect views of the Pyramids, I thought. 

Continue reading “Instagram Diaries 3 – Day One and My First Pics”

Instagram Diaries 2 – Creating and Instagram Business Account, Getting the Perfect Username and Profile Image

If  you missed Part 1 of the Instagram Diaries – how it all began – you can click here!

Well, here we go.

One of the benefits of not being 20 year old me is that I am a little more cautious and less willing to trust my abilities in favor of listening to successful people and following their advice. 

Okay, I fess up. I am more likely to research and take others peoples advice more than I did twenty years ago. There!!! Is that okay? Jeez!!!

So the gurus of Instagram, those twenty-teen titans, were telling me that I should either upgrade my current Instagram account or create a new account.

Hmm… the though of updating my personal Instagram account and dicking around with all sorts of marketing tests did not seem fair to the few friends who bullied me into joining Instagram against my will in the first place.

Plus I got a bit of a confession to make…

Continue reading “Instagram Diaries 2 – Creating and Instagram Business Account, Getting the Perfect Username and Profile Image”

Instagram Diaries 1 – Getting Started

This might just be my midlife crisis! The start of my bumbling adventure on #Instagram

This might just be my midlife crisis!

A little over a month ago I turned 40. I could tell I was going to hit the big four-oh because of all the aches and pains that take longer and longer to deal with than they used to. 

On top of that, the new workload got hard. I mean real hard. I’m used to pulling 10+ hour days once or twice a week, but this year, it’s been every single day.

I know I needed a side project that was fresh and light. I needed a break from the coding and spreadsheets. Like any bloke in his midlife crisis, I needed to go out here and hit the latest young thing in a sad and desperate effort to rekindle my youth. 

That young thing, I thought, would be Instagram. Now, I know Instagram is no baby, but we need to to talk comparatively here. I’m on that slow rise to the “Old Fart” zone and five years older than 90% of the demographic

So to prove my youth one last time (maybe), I set out to learn what I could about Instagram. What I didn’t expect was the utter amount of information, and a lot of it data driven too! I was really starting to warm to the idea.

Continue reading “Instagram Diaries 1 – Getting Started”

Google Apps Script: Get File By Name – With Optional Parent Folder Crosscheck

Google Apps Script

One of my recent projects in Google Apps Script required me to search for a file by name and get its ID. This can be problematic in Google Drive because you can have multiple files of the same name in multiple locations. My solution was to also check the file’s parent folder name as well. 

I created a function getFileByName() to handle this. The function takes the following parameters:

  • fileName – The name of the file you are looking for. (required)
  • fileInFolder – The parent folder of the file your are searching for. (optional)

The file path would look a little something like this:

.../fileInFolder/fileName

getFileByName() returns an object containing :

  1.  the ID of the file if the file exists or false if it does not.
  2. the ERROR if there is an error or false if there is not. 

The returned object would look like the following:

Successful

Error

getFileByName() reports the following errors:

  1. If no parent folder name is given and there are more than one file with the same file name. 
  2. There is more than one parent folder and file combination with the same name.
  3. There are multiple files with the same name but none are in the folder parent name provided.
  4. No file with the file name provided exists.

Continue reading “Google Apps Script: Get File By Name – With Optional Parent Folder Crosscheck”