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

5 ways to create an ordered alphanumeric list in Google Sheets

For whatever reason, sometimes we just need a list of alphanumeric letters and numbers like this “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ” to run down a column or across a row, or just all packed into one string of text in a cell in our Google Sheet.

I most commonly use an alphanumeric list to index data or use an alphanumeric string in the random assignment of a value.

In this tutorial, we will cover 4 ways to achieve this. Some approaches have different benefits than others. While two of the approaches even use the new Google Sheets LAMDA function.

If you just want to dive in, copy the formula, and get back into your own project, click on the link to the main numbered headers in the table of contents below. You can copy the formula into your project using the copy symbol in the dropdown menu of the formula bar and selecting the formula you want.

Each formula type can be:

  1. Transposed to run across a row.
  2. Join into a string in a cell.
  3. Set to lowercase.
  4. Extended to include a lowercase option.

The How it Works sections are not mandatory reading but might be helpful if you plan to extend the formula or are simply curious.

Oh, and number 1 is my favorite.

Continue reading “5 ways to create an ordered alphanumeric list in Google Sheets”

Create links to the first item of each group in Google Sheets

Imagine you have a Google Sheet tab containing a course worth of hundreds of students sorted into classes or groups. After each exam, quiz or assignment, your teacher for each class needs to enter in the grades.

To make life easier for your teachers, we want to create a summary page where we can click on their class and be navigated directly to their group.

We don’t want to have to manually create a link for each location so we are going to write a formula to do the work for us.

Now, the formula is a little complex. So first off, we will generate our list of classes and add a separate section start link for each one. Then we will combine the two together to generate a single formula that gets all the unique sections and provides a link for each one.

If you are playing along, you can grab a copy of the starter sheet here:

STARTER SHEET

Continue reading “Create links to the first item of each group in Google Sheets”

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

How to Easily Calculate Sales Tax (GST 🦘) in Google Sheets

Adding tax to the sales price or subtracting tax from a total price of an item in Google Sheets (GST)[Update 16 Jul 2022]

We have Goods and Services Tax (GST) here in Australia; it is a sales tax on all sorts of things. You might have something similar in your own country. If our business turnover is more than $75,000 AUD for the year we need to register to pay this GST. This means that we have to include the tax in the total value of an item. In this tutorial, I’ll show you how to do this quickly in Google Sheets.

You can calculate the Total Price of an item including Sales Tax in two ways:

  • Add tax to the sales price: Sales Price + Sales Tax = Total Price
  • Subtract tax from the total price: Total Price – Sales Tax = Sales Price

Adding Tax to the Sales Price

This is the easiest and often most common approach. Here we set a sales price and then calculate how much tax needs to be applied to the total price.

Let’s say we have $100 and we need to add 10% tax to our total price.

Calculating the taxable amount of a value in Google Sheets step 1

First, we get the amount of tax we need to add. We do this by multiplying the Sales Price by the Tax percentage.

Sales Price = Sales Price × Tax percentage/100

Sales Price = Sales Price × Tax as a decimal

10 = 100 × 0.1

If you have set up the formatting of your cells in your Google Sheet as I have in the image above where the format for A2 is dollars ($) and B2 is a percentage (%) then you don’t have to worry about converting the percentage to a decimal. Google Sheets will handle that for you. Take a look at the formula:

=A2 * B2

=100 * 0.1

=10

Calculate the taxable percentage portion of a value in Google Sheets

Note that we use the asterisk symbol (*) in Google Sheets (and in most digital calculations) to multiply items.

All we then need to do is add the Sales Price to the Sales Tax:

= A2 + C2

= 100 + 10

= 110

Add the sales price to the tax added to the item in Google Sheets

We can combine both formulas like this:

= Sales Price + Sales Price * Sales Tax

= A2 + A2* B2

= 100 + 100 * 0.1

= 110

Adding sales tax to an amount in Google Sheets

Remember that in our order of operations in maths the multiplication of the Sales Price by the Tax rate as a decimal will occur before adding the Sales Price.

Practice: Go ahead and try and change the Sales Price or Tax % and see what results you get.

Adding Sales Tax Video

Subtracting Tax From the Total Price

Sometimes we don’t want to change the price of an item for a customer, so we will subtract the amount to tax from the original price that we offered them.

Say that we have been selling a widget for $100, but now we have reached the GST threshold and need to include sales tax on the item. Our customers are going to be cranky with us for adding an extra $10 bucks onto the price. Instead, we decide to include the tax in the $100 sales price of the widget.

So, how do we do this?

This time we start off with the Total Price and the Sales Tax.

Subtracting the sales tax from the total price of an item in Google Sheets Part 1

We’ve used the same example before, where our total price is $100.00 and our tax rate is 10% on the item.

To calculate the Sales Tax included in the Total Price we divide the total price by, one plus the tax rate as a decimal multiplied by the tax rate as a decimal.

Total Price /( + Tax as decimal) * Tax as decimal

= A2 / (1 + B2) * B2

= 100 / (1 + 0.1) * 0.1

= 100 / 1.1 * 0.1

= 9.09

Calculate the tax included in the total value of an item in Google Sheets

Then to get the Sales Price, simply subtract the Total Price from the Sales Tax:

= Total PriceSales Tax

= A2C2

= 1009.09

= 90.91

Calculate the sales price after tax based on a total price value in Google Sheets

Subtracting Tax Video

Get The Google Sheets Sales Tax Calculator

Google Sheets Sales Tax Calculator

You can grab your very own copy of the Google Sheets Tax Calculator here. Plus there are Google Sheet tabs with the examples above included.

Google Sheets Sales Tax (GST) Calculator

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

Changelog

  • 2022-07-16: Added two videos. One for each section of the tutorial.