Replied to https://ckarchive.com/b/0vuwh9holzx0ps7mggrmzhv57o555fn (ckarchive.com)

In this newsletter, we’re looking at how to use hyperlinks in Google Sheets. And, if you’re an advanced user, I’ve got a spicy formula for you at the end of the newsletter.

Sheets Tip #312: The Missing Link πŸ”— by Ben Collins


Ben, I really like the spicy solution regarding hyperlinks:

=HYPERLINK( "#gid=0&range=A" & ArrayFormula( MAX( IF( ISBLANK(A2:A), 0, ROW(A2:A))))+1 , "Add Data")

I had never thought about the fact that you can reference a cell and what possibilities that may allow.

It had me wondering about linking to a cell in a table via a drop-down menu / wild card search using the MATCH function to add a link to a table row:

=HYPERLINK("gid=0#gid=0&range=B" & MATCH(B$1, 'Sheet1'!B2:B, 0) + ROW('Sheet1'!B2) - 1, B1)
Bookmarked https://scripteverything.com/merge-two-columns-using-query-google-sheets/ (scripteverything.com)

So if we wanted to get all the elements within our column wrapped into one row we would just need to change that third parameter to the maximum height of our columns. We could use the

ROWS()

function to capture this number:

Merge Two Columns Using QUERY: Google Sheets (Step By Step Example) by Ryan Sheehy


I have a QUERY that I wanted to display in one column so that I could roll the results up into one cell to copy and paste elsewhere. I found this guide to combining columns and simply transposed the data to get the outcome I was after:

=JOIN(CHAR(10),TRANSPOSE(QUERY(TRANSPOSE({"","","","","","";"Record(s) updated / merged:","","","","","";"","","","","","";SORT(Indirect(Table1));"","","","","","";"Record(s) retained:","","","","","";"","","","","",""; SORT(Indirect(Table2))}),,ROWS(TRANSPOSE({"","","","","","";"Record(s) updated / merged:","","","","","";"","","","","","";SORT(Indirect(Table1));"","","","","","";"Record(s) retained:","","","","","";"","","","","",""; SORT(Indirect(Table2))})))))
Replied to Creating a Catalogue in Google Sheets by Aaron DavisAaron Davis (readwriterespond.com)

I was recently asked to have a look at spreadsheet that listed all the guides and videos located in a support folder as a reference. This folder also included a number of folders within folders, which created a level of complexity.
The current workflow involved using an Add-on File Cabinet from the …

I recently discovered that Awesome Tables’ Filing Cabinet Add-on has been deprecated, this broke the catalogue I had created with Google Sheets.

Message from Awesome Tables about the move to a paid add-onI searched online for any further explanation on the change, but was simply sent to Awesome Tables support page.

I started exploring other options online and short of paying for API connectors, I could not really find anything. I subsequently turned to CoPilot, wondering what it might give me. Surprisingly, it gave me a basic script for everything that I needed.

function listFilesInFoldersGEN() {
  var folders = [
    {folderId: 'URL', sheetName: 'General'},  
    // Add more folders as needed
  ];
  
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  
  for (var i = 0; i < folders.length; i++) {
    var folderId = folders[i].folderId;
    var sheetName = folders[i].sheetName;
    var folder = DriveApp.getFolderById(folderId);
    var sheet = spreadsheet.getSheetByName(sheetName);
    if (!sheet) {
      sheet = spreadsheet.insertSheet(sheetName);
    }
    
    // Save the existing data
    var range = sheet.getDataRange();
    var values = range.getValues();
    
    try {
      sheet.clear();
      sheet.appendRow(["Name", "Date", "Size", "URL", "Folder"]);
      listFilesInFolderRecursiveGEN(folder, sheet, folder.getName());
    } catch (e) {
      // If an error occurs, revert to the saved data
      range.setValues(values);

      // Log the error
      var errorMessage = 'Error: ' + e.toString();
      Logger.log(errorMessage);
      
      // Send an email
      var emailAddresses = ['bwillis@edu.au', 'nlapin@edu.au']; 
      // Enter your email address here
      var subject = 'Error in Support Catalogue - General script';
      var body = errorMessage;
      MailApp.sendEmail(emailAddress, subject, body);
    }
  }
}

function listFilesInFolderRecursiveGEN(folder, sheet, path) {
  var files = folder.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    sheet.appendRow([file.getName(), file.getDateCreated(), file.getSize(), file.getUrl(), path]);
  }
  
  var subfolders = folder.getFolders();
  while (subfolders.hasNext()) {
    var subfolder = subfolders.next();
    listFilesInFolderRecursiveGEN(subfolder, sheet, path + '/' + subfolder.getName());
  }
}

After a bit of back and forward, I had a new working catalogue which I provided to the team to provide feedback on.

Replied to AI + Google Sheets: How To Use Them Together by Ben Ben (benlcollins.com)

See how AI tools work with Google Sheets to boost your productivity. Covers ChatGPT, Google Bard, and AI add-ons.

I really enjoyed how you broke down the different uses for AI in this post Ben. Personally, I have found myself using Co-Pilot to come up with formulas as this is what I currently have access to. For me, I often have an idea of what is possible, but do not always have the time or mental space to dig into the formulas to find the right solution. I have found it useful then to just ask Bing. I am now finding myself teaching colleagues how to use prompts to not only find a solution, but have it explained for them.
Replied to

Thanks Ben for sharing this explanation about the difference between QUERY and CHOOSECOL. It was the first thing I though when reading your newsletter.
Bookmarked How to change Google Sheets date format and convert dates to numbers and text by Natalia Sharashova (ablebits.com)
I never cease to be surprised with what I can do with the QUERY formula in Google Sheets. I had a problem today where I wanted to match two datasets using the date column. The problem was that they were in two different formats. So I started searching. Low and behond, I discovered that you can in fact format using the QUERY format. The formula looks something like this:

=QUERY(A1:C7,"select * format B 'd-mmm-yy (ddd)'")

These are the available values:

  • d | Day without a leading zero for 1-9 (i.e. 7)
  • dd | Day with a leading zero for 1-9 (i.e. 07
  • ddd | Day as an abbreviation (i.e. Wed)
  • dddd | Day as a full name (i.e. Wednesday)
  • m (if not preceded or followed by hours or seconds) | Month without a leading zero (i.e. 8)
  • mm (if not preceded or followed by hours or seconds) | Month with a leading zero (i.e. 08)
  • mmm | Month as an abbreviation (i.e. Aug)
  • mmmm | Month as a full name (i.e. August)
  • mmmmm | First letter of the month (i.e. A)
  • y or yy | Two digit year (i.e. 19)
  • yyy or yyyy | Full numeric year (i.e. 2019)

I know Ben Collins has spoken about formatting dates before, but I never knew there were all these options.

Bookmarked Creating an xml file with a script from google spreadsheet (Stack Overflow)

You need to create an xml file with a script from google spreadsheets. I use the code from these two topics:

Google Script Export Spreadsheet to XML File

Looking to create an XML feed from a Google Sheet Table

I was asked about the ability to export the results from a Google Form as an XML file. I found this script which gets me part of the way there, I just need to work out how do produce child elements.
Replied to

Ben, I love the use of grouping columns, but found it problematic when sharing a Google Sheet as it is not unique to the user.
Replied to Creating a Catalogue in Google Sheets by Aaron DavisAaron Davis (readwriterespond.com)

To create theΒ SWITCH, I created a UNIQUE list of all the folders and then pasted them as values so that I could delete those not required to be displayed in the directory. After culling the list, I then added the area in the cell next to each folder. Once I had these two columns complete, I usedΒ this formulaΒ to add quotation marks to them all:

=ArrayFormula(“”””&Sheet1!A:D&””””)

I then copied this list into the SWITCH formula and added in the commas

I have found a cleaner method for adding in the commas and quotations required for the SWITCH formula:

=char(34)&join(""",""",ARRAYFORMULA(QUERY(A1:A,"SELECT A WHERE A IS NOT NULL")&""","""&QUERY(B1:B,"SELECT B WHERE B IS NOT NULL")))&char(34)
Bookmarked Sheets Tip 212: Single Formula Year Calendar! (ckarchive.com)

At the heart of today’s tip is the fantasticΒ SEQUENCE function.

In a blank Google Sheet, enter this formula into cell A2:

=SEQUENCE(53,7,DATE(2022,1,1),1)

It outputs a year of dates across 7 columns!

Add the days of the week as a header row and you’re set.

Ben Collins shares a means of creating a year calendar:

=SEQUENCE(53,7,DATE(2022,1,1),1)

Bookmarked

Ben Collins provides a formula for generating a list of IDs or numbers dependent on how many items are in the list using the Sequence formula:

=ArrayFormula(SEQUENCE(MAX(ROW(B2:B)*(B2:B<>""))-1))

Replied to A Guide To Named Functions In Google Sheets (New For 2022!) – by Ben Ben (benlcollins.com)

Named functions in Google Sheets let you create and name custom functions built with regular formulas, and reuse them in other Sheets.

Ben, am I right to say that Named Functions allows the functionality that is available via Google Scripts, it just means that you do not have to go through the effort of creating the script? I am assuming that if I made a copy of a Sheet with a Named Function that this comes with the copy? I also assume that unlike with Google Scripts, there is no need to provide permission for Named Functions? I am left wondering about combining the use of macros and Named Functions.
Bookmarked Send email when a Google Sheet is edited (spreadsheet.dev)

Suppose you’re a school teacher and you’re planning an upcoming Parent-Teacher conference. Instead of using a printed sign up sheet, you decide to use a Google Sheets spreadsheet where parents can sign up for a meeting slot.

In the past you’ve had parents forget which slot they signed up for so you’re hoping that a shared Google Sheet that they can access at any time will help solve this problem. You also want to receive an email notification whenever a parent signs up for a slot. This will help you keep track of who hasn’t signed up yet so you can remind them when they drop off or pick up their kids.

In this tutorial, I’ll show you how to send email notifications whenever a Google Sheets spreadsheet is edited. We’ll use Google Sheets and some Google Apps Script code to create this “application”.

Although there is a built in Notification Rules within Google Sheets, one of the limitations is that it does not actually stipulates what has changed. I subseqently found this guide for creating a script to send an email when a Google Sheet is edited, as well as this solution to sending to multiple users.

"example@gmail.com" + "," + "example@yahoo.com";

The next step is to think about how this information can be made clearer, possibly listing the specific changes, rather than just highlighting the particular school updated.

Replied to

Not sure about Excel, but pretty confident I could do it with Google Sheets using QUERY formula. Are the datasets public on the web?
Bookmarked Font weight BOLD using formula in cell (Stack Overflow)

How to style from formula in cell?

Two solutions provided for bolding text in Google Sheets.

The first using SUBSTITUTE of one font to another:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(E3,"A","𝐀"),"B","𝐁"),"C","𝐂"),"D","𝐃"),"E","𝐄"),"F","𝐅"),"G","𝐆"),"H","𝐇"),"I","𝐈"),"J","𝐉"),"K","𝐊"),"L","𝐋"),"M","𝐌"),"N","𝐍"),"O","𝐎"),"P","𝐏"),"Q","𝐐"),"R","𝐑"),"S","𝐒"),"T","𝐓"),"U","𝐔"),"V","𝐕"),"W","𝐖"),"X","𝐗"),"Y","𝐘"),"Z","𝐙"),"0","𝟎"),"1","𝟏"),"2","𝟐"),"3","πŸ‘"),"4","πŸ’"),"5","πŸ“"),"6","πŸ”"),"7","πŸ•"),"8","πŸ–"),"9","πŸ—")

The second solution combines REGEX and UNICODE:

=ARRAYFORMULA(JOIN("", UNICHAR(QUERY(UNICODE(SPLIT(TRANSPOSE(SPLIT(
REGEXREPLACE(
REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(A2&""
,"([^a-zA-Z0-9])","$1"&UNICHAR(160)&UNICHAR(1)&CHAR(127))
,"'","''")
,"([a-z])","$1"&UNICHAR(160)&UNICHAR(119738)&CHAR(127))
,"([A-Z])","$1"&UNICHAR(160)&UNICHAR(119744)&CHAR(127))
,"([0-9])","$1"&UNICHAR(160)&UNICHAR(120735)&CHAR(127))
,"'","''")
,CHAR(127))), UNICHAR(160))), "select Col1+Col2-1 label Col1+Col2-1 ''",0))))

I prefer the second solution. However, the first is easier to apply to a whole column using the ARRAYFORMULA.

Replied to

Ben, I am intrigued on your QUERY / MATCH combo. Have you written about adjusting the columns? I would love to see a full formula. I have long tried to make a formula that allows me to select which columns to include via a checkbox. However, I can never quite get it to work.
Replied to How To Create A Select All Checkbox in Google Sheets (benlcollins.com)

Learn how to create a select all checkbox in Google Sheets using a clever IF formula and checkboxes with custom values.

I really like checkboxes and have found myself using them more and more. I found this script which I use to clear all my selections, but may need to rethink my solution based on your solution.