How do I reverse a range by Rows or Columns in Google Sheets

Google Sheets: SORT, INDEX, ROWS

Reverse Rows in Column in Google Sheets
My favourite Killjoy members. Column A – From most favourite. Column B Saving the best for last.

Sometimes you have a need to reverse a list quickly in Google Sheets.

That’s pretty easy to do if the list is sorted alphabetically. Just go on into the <Data> menu and choose from one of the sort functions. But what if the data you want to flip is not in alphabetical or numeric order?

Below are 3 ways to reverse your data:

Also check out the last example on how to flip a column in Google Sheets.

For the examples below, I’ll be using a list of my favourite Killjoys characters. Yeah, I’m a sci-fi geek.

Continue reading “How do I reverse a range by Rows or Columns in Google Sheets”

Add the Current Date to a Sheet When Data Is Added So That The Date Does Not Change(Static) – Google Sheets (Updated July 2023)

Google Sheets, Google Apps Script: onEdit

You’ve probably come across the problem where you need to know when a piece of data has been added to your spreadsheet. You probably have been equally frustrated that there is no out-of-the-box function that will do just this.

You’ve tried TODAY() and NOW(), but they change dynamically. What you really need here is something that does not change.

Let’s look at two workarounds that can help you out with this problem.

Continue reading “Add the Current Date to a Sheet When Data Is Added So That The Date Does Not Change(Static) – Google Sheets (Updated July 2023)”

Google Apps Script – How to Automatically Generate a Time From a Four Digit 24 hour Time in Google Sheets.

Google Apps Script, Google Sheets

On a recent board post, a Google Sheets user wanted to change a four-digit number (for example, 1230) to a time, like 12:30, in the same cell that the item was entered.

Unfortunately, the user was not in a position to change the starting values, so they were left with the 4 digits.

There are two ways of doing this with varying levels of complexity:

 

  1. The Google Sheets Formula Approach
  2. The Google Apps Script onEdit Approach

Continue reading “Google Apps Script – How to Automatically Generate a Time From a Four Digit 24 hour Time in Google Sheets.”

Create a Dynamic Password Generator in Google Sheets

I need to create a lot of sample data for tutorials and courses. One of the things that I needed for a recent course I am building was to generate a column containing dummy passwords in Google Sheets. Each password needed to consist of letters, numbers and characters.

Usernames and Passwords in Google SheetsUntil recently, this task would have been relegated to Google Apps Script.

However, with the recent introduction of the LAMBDA function (Well, at the time of writing this anyway), we can do so much more with our Google Sheets.

Before we dive into the formula, it’s important to understand that these ‘passwords’ or random strings of characters are dynamically generated. This means every time you update a cell or reload your Google Sheet the characters in each cell will change.

So once you generate your passwords, copy the range and paste the values back in (Ctrl + c, Ctrl + Shift + v). This way only the values remain.

If you just want to grab the formula and be on your way, you can copy it from the section below. However, if you want to learn how it all works, read on for a breakdown.

The Password Maker Formula

Note in the formulas below there are three parameters that you can change:

  1. [NumChars]: The number of characters in each string in each cell.
  2. [NumRows]: The number of rows to produce the random string of characters in.
  3. [NumCols]: The number of columns to produce the random string of characters in.

Replace the items in the square [] braces with your own values.

For example, if we wanted to generate a matrix of passwords 4 rows deep, 5 columns wide and with each cell containing 12 random characters we would do this:

Matrix of passwords generated in Google Sheets
Matrix of passwords generated in Google Sheets

Use just numbers, numbers and letters, etc.

To quickly change the formula to produce only a certain subset of characters, you will need to delete the desired characters from the string contained in the MID function on line 14 of the example above.

You will also need to change the second argument of the RANDBETWEEN function to the length of your new string of characters.

Hint! You can quickly count the string of characters by copying the characters in the formula (including the double quotation marks on each end) and pasting it inside a LEN function. For example:

=LEN("GOAT!1234") = 9

Check out the sample sets below and their letter lengths for convenience.

Name Character Set Length
Numbers “0123456789” 1o
Letters
UPPER
“ABCDEFGHIJKLMNOPQRSTUVWXYZ” 26
Letters
lower
“abcdefghijklmnopqrstuvwxyz” 26
Letters UPPER
and lower
“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz” 52
Alphanumeric
UPPER
“0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ” 36
Alphanumeric
lower
“0123456789abcdefghijklmnopqrstuvwxyz” 36
Alphanumeric
UPPER & lower
“0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz” 62
Characters only “~!@#$%^&*()_-+{[}]|\:;<,>.?/" 29

 

Formula Breakdown

In this section, we will walk through the process of creating the random string generator. Not only does this help to provide an understanding of how the formula works, but it also gives you some insight into a good workflow for building your own complex formulas in Google Sheets.

The Video

The Starter Sheet - To Play Along

If you want to get hands-on to make things more fun, grab the starter sheet from here:

RANDOM STRINGS - Starter Sheet

I'll be referring to locations in the starter sheet as a part of the walkthrough below.

The Character List

Our character list is as follows:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&*()_-+{[}]|\:;<,>.?/

Place the list in a separate cell so you can reference it during testing. In the example (The Starter Sheet), I have added this to cell B2.

If you want to learn how to create a character list with a formula check out the tutorial below:

5 ways to create an ordered alphanumeric list in Google Sheets

Get the length of characters

The first thing we need to do is get the total number of characters in our list. This number will be used in another formula later.

We can do this quickly with the LEN function which gets the length of a string.

In our example I reference the string in cell B2 and apply LEN to it:

= LEN(B2) = 91 

Get the total length of a string in Google Sheets with the LEN function
Click to Expand!

Select a Random Character from the String

RANDBETWEEN

We can select a random number from between 1 and 91 with the RANDBETWEEN function.

Check out this tutorial for an advanced use of RANDBETWEEN Skewed Random Range in Google Sheets (RANDBETWEEN)

This function takes two arguments, the starting value and the end value. Let’s input our range:

=RANDBETWEEN(1,91) = A random number between 1 and 91

It will dynamically return a random value between 1 and 91.

Note! The Google Sheets RANDBETWEEN function updates dynamically. This means that every time you apply a change to your sheet the random number will change. 

MID

We can then use the MID function to find a character in the string at a designated position. For us, this position will be determined by the number that our RANDBETWEEN function returns.

MID takes 3 variables:

  1. The reference string or cell.
  2. The start index in the cell that contains the string.
  3. The length of characters to extract.

So in our example, our formulas would look like this:

=MID(B1, RANDBETWEEN(1,91),1) = A random character from our string.

Where B1 in our example is the string of characters.

Get a random character from a cell containing a string in Google Sheets

You can see in the example above that the formula randomly selected the pipe (|) characters from the string in B1.

Set a Sequence of n Columns

Let’s work on another part of the formula now. We need a way to create a string of random characters at any length we desire – we’ll call this n.

The first part of this process is to generate a row that is cells wide.

This can be achieved with the SEQUENCE function. With this function, we can generate a range or matrix of values at any row or column width.

The SEQUENCE function takes 4 arguments:

  1. Number of rows: For us, this will always be 1.
  2. Number of columns: We will assign our desired n length here.
  3. The Starting value (optional): This will always be 1 in our formula.
  4. The Step between each value (optional): This will also always be one in our formula.

Let’s say we want to create a formula one row deep and five columns across:

=SEQUENCE(1, 5, 1, 1) = Array [1, 2, 3, 4, 5]

Create a SEQUENCE in Google Sheets

Map a Random Character to Each Sequence Item

Now that we have our sequence, we can map a random character to each item in the sequence. To do this we use the Google Sheets MAP function. This is a helper function of the LAMBDA function set.

The MAP function allows you to traverse an array and modify each item in the array. For us, we are going to apply a random character to each item in the sequence we generated.

MAP can take a number of arrays or ranges as its first argument and then a LAMBDA function as its last argument.

The nested LAMBDA array takes an iterator item argument. This represents the current cell the item is modifying as it works through each item in the range. We need to add this argument even if we don’t use it in our formula.

The second LAMBDA argument is the formula expression. That is, what we are doing to change the value in each of the cells.

=MAP(array,LAMBDA(iterator argument, formula expression)

For us, our first argument is our SEQUENCE, and our formula expression is our MID-RANDBETWEEN combo.

=MAP(SEQUENCE(1,5),LAMBDA(cell, MID(B1,RANDBETWEEN(1,91),1)))

Google Sheets MAP a random array of characters

Note that we can always change the second argument of the SEQUENCE to change the number of columns containing random characters.

Join the array of random characters into one  password string

We can combine our random character array into a single string of characters to generate a password with the JOIN function.

JOIN takes two arguments:

  1. The delimiter – This is the value we want to use to separate each cell item when we combine it into a string. In our example, we don’t want to separate the characters so we will leave this as an empty string.
  2. The array – This will be the array we generated in the previous section.

=JOIN(delimiter, array)

=JOIN("",MAP(SEQUENCE(1,5),LAMBDA(cell, MID(B1,RANDBETWEEN(1,91),1))))

Google Sheets JOIN a MAP of a random array of characters

If you just want a single password, then this is a pretty good place to stop, but if you want a bunch of passwords across columns and rows, read on.

Generate an Array of Passwords

We can use another LAMBDA helper function for us to create an array n rows deep by rows wide. To do this we can the MAKEARRAY function.

As the name suggests, MAKEARRAY generates a 2-dimensional array of data generated by whatever is in the contained LAMBDA function.

MAKEARRAY takes three arguments:

  1. Number of Rows: How many passwords deep that we want to run.
  2. Number of  Columns: The total number of passwords we want to run across our Google Sheet.
  3. The LAMBDA function: The MAKEARRAY lambda function also requires three arguments:
    1. The Row Argument: We won’t use this or the Column argument, but they are mandatory for a MAKEARRAY function. We’ll call this argument row_index.
    2. The Column Argument: Again, this is not needed for our password maker, but we will name this argument column_index.
    3. Formula Expression: Here we can insert our password generate from the previous section.

We will also add the string data now into our entire formula. We don’t need to keep it separate.

Google Sheets MAKEARRAY password generator

In the example above we have created an array two columns wide and five columns deep with a random password length of 5 characters (See the second argument of the SEQUENCE)..

Conclusion

This password generator is a really helpful tool for templating spreadsheets to create examples or quickly generate a password or random string of characters for codes.

As we mentioned above, the passwords will change each time you update the sheet. The best solution to provide a static password would be to use a bit of Google Apps Script Magic connected to an onEdit() function similar to this tutorial:

Add the Current Date to a Sheet When Data Is Added So That The Date Does Not Change(Static) Google Sheets (Updated January 2022)

If you have found the tutorial helpful, why not shout me a coffee ☕? I'd really appreciate it.

Did you enjoy the tutorial? Want to upskill and get a solid step-by-step course to become a pro at Google Sheets? Check out my course, Google Sheets: Learn the Essentials with Three Detailed Projects. Sign up today.

 
Google Sheets Shortcuts Mousepad
Google Sheets Shortcuts Mousepad
Want a fast track to boost your Spreadsheet efficiency? Grab one of these handy Google Sheets Shortcuts mousepads that I created from my store.
Google Sheets Shortcuts Mousepad Gel
Google Sheets Shortcuts Mousepad Ge

 

~ Yagi

Adding Links to Images and Buttons in Google Sheets

Have you ever tried to add a link or URL to an image in Google Sheets only to discover it is deleted and replaced by just the URL? It’s a pain.

In this tutorial, we will cover a few simple approaches to adding links to images in Google Sheets.

First, we will cover an approach using formulas and then we will use a sneaky approach using a bit of cell and image manipulation.

If you have come to this tutorial looking for a Google Apps Script solution, well… 1) I would discourage it, but 2) if you really must, check out the link to this tutorial for a hacky workaround.

On with the show!

The Formula Approach

In this example, we will use the IMAGE and HYPERLINK Google Sheets functions.

If you want to play along here is a link to the Starter Google Sheet:

Addling links to images in Google Sheets – Starter

(Select both the image and the Google Sheet, right-click and select ‘Make a copy’)

The basic pattern is as follows:

=HYPERLINK("URL - Link",IMAGE("URL to your image"))

Working from the inside out, the IMAGE function requires a link to the image that is being used. There are a number of ways of getting this link that I will cover in a  moment.

The HYPERLINK Google Sheets function takes the destination link as its first argument and then and then a link label as its second argument. Generally, this argument is text, but we can coerce this label into an image by replacing it with our IMAGE function.

But how do we get the image URL?

Image from an external website

If you store your images on a personal website or from some online photo hosting sites you can get the link to the image.

In the example below, I have a link from my website to my image. I want to use that image as my URL label. This is what my image link would look like:

=HYPERLINK("https://yagisanatode.com",IMAGE("https://yagisanatode.com/wp-content/uploads/2022/05/yagisanatodeSiteBanner_titleOnly-500-width.jpg"))

This will result in this image link:

Adding a link to an image in Google Sheets_image url is external
Click to Expand!

Image from Google Drive

Unfortunately, we can’t just go to Insert > Image > Insert image in cell for this. Nor can we go to our Google drive, select the image share it and get the URL from the share.

It won’t work.

There are a couple of workarounds for this, but probably the easiest approach is to open the image in a drawing.

Here is how we do it:

    1. Navigate to the Google Drive folder where your image is saved.
    2. In a blank space in the folder right-click > More… > Google Drawings

      Creating a Google Drawing File in Google Drive
      Click to Expand!
    3. Inside Google Drawings select Insert > Image > Drive.
      Insert an image into Google Drawings
    4. A sidebar will appear. Navigate to your image and double-click it. It will load into your drawing.
      Insert an image into Google Drawings select from drive
    5. Holding the left mouse button down, drag the image up to the top-left corner of the drawing.
    6. You will notice a checkered grey and white area in the background, this is the page area. We want the page area to be equal to the image. In the bottom right of the page area, there is a little move triangle-shaped button click and drag it up to match the size of the image.

      Resizing the Google Drawing page
      Click to expand
    7. In the top right of the Drawing app, rename it by clicking on the top-left text where it says “Untitled”. Make sure it is something meaningful for your task.
    8. Now we get the URL for the image. Select File > Share with others > Publish to the web. 
    9. A dialogue box will appear. Make sure Link is selected, choose your preferred size and then select Publish.
      Google Drawing Publish to the web as a link
    10. You will get an alert that comes down from the top of the page making sure you want to publish this image. Select Ok.
    11. You will now have a Google Drawing URL. Hit Ctrl + C  (⌘ + C) to copy it.
    12. Head back to your Google Sheet and insert it into IMAGE function. It should look similar to this:

=HYPERLINK("https://yagisanatode.com",IMAGE("https://docs.google.com/drawings/d/e/2PACX-1vR2MqTAC_SBvvoWlAwLL_Pk5gHbLzOb0CJAOvbxitdNvstsX477fX8xRqvvQDOohuF83Ie4UQS4AQvk/pub?w=502&h=503"))

Adding a link to an image in Google Sheets_Google Drawing URL

You can also do the same thing with custom drawings and buttons using Google Drawing. Check out the video below for a demonstration of this.

If you have found the tutorial helpful, why not shout me a coffee ☕? I'd really appreciate it.

The video

The sneaky approach to adding  Links to images.

Another approach to adding links to images in Google Sheets that you may want to consider is to add a URL to a cell that you want to use for your image and then insert an image over cells. Then move that image so that it fits inside the cell with the URL.

When a user clicks or hovers over the cell and image the link will appear.

Here are the detailed steps:

  1. Select a cell. If you want something larger, you may have to merge cells together to make it just right.
  2. Add your URL to the selected cell.
  3. Change the text colour of the cell to match the background colour. This will hide the URL just in case you didn’t fit your image in perfectly.
    Adding a link to a cell in google sheets
  4. Now go to Insert > Image > Insert image in cell
    Insert image over cells in Google Sheets
  5. Select your image from your desired location.
  6. One the image appears in the Sheet, move the image to the cell with the link and resize it so that it fits just inside the cell. Note! You should leave a tiny bit of space from the edges of the cell so that the URL is picked up.

The end result should look a little like this:

Sneaky image with URL in Google Sheets

That’s all there is to it.

The Video

Did you enjoy the tutorial? Want to upskill and get a solid step-by-step course to become a pro at Google Sheets? Check out my course, Google Sheets: Learn the Essentials with Three Detailed Projects. Sign up today.

 
Google Sheets Shortcuts Mousepad
Google Sheets Shortcuts Mousepad
Want a fast track to boost your Spreadsheet efficiency? Grab one of these handy Google Sheets Shortcuts mousepads that I created from my store.
Google Sheets Shortcuts Mousepad Gel
Google Sheets Shortcuts Mousepad Ge

~Yagi