Cell notes only show up when you hover over a cell. This isn’t very conducive when there are multiple cell notes to analyze. However, it is possible to extract those cell notes into another column by using the Google Apps Script GetDataRange Function.
So let's get started on learning how to use the App Script getdatarange function.
What are Google Sheet Cell Notes?
Google Sheets Notes are simply little text boxes added to the cell which just add extra information. These are viewed by hovering over the cell.
Step 1: Sample Google Sheet
The Google Sheet that I will be using is this blog, which contains the following details:
- Name of the city
- Name of the product
- Quantity sold
- Total price sold
- Category of the product
Step 2: Add Google Sheet notes
If you want to know how to add note in Google Sheets, follow these steps:
- Right-click on the cell, you want to add the note in.
2. A text box will appear on clicking Insert note.
3. Add the required text in the cell note.
4. Here you have successfully added a note to the cell.
Step 3 : Write the automation script using Getdatarange in Google Apps Script
While you are in the sheet, launch the Apps Script Editor.
To do that:
- Click on the tools button next to the Add-ons button.
2. Next click on the Script Editor option. This brings up the Script Editor as shown below.
We have reached the Script Editor. Let’s Code using various functions such as getActiveSpreadsheet, getActiveSheet, getNotes, and getCell.
function getNote()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getDataRange();
var notes = range.getNotes();
for(var i = 0;i < notes.length;i++){
for (var j = 0; j < notes[0].length; j++){
if(notes[i][j]){
var note = notes[i][j];
var cell = range.getCell(i+1,j+1);
cell.offset(0,1).setValue(note);
}
}
}
}
Declaring the function:
- Get the Active Spreadsheet
- Get the Active Sheet(Since we have only one sheet)
- Get the data range
- Get the notes in the range
The cell notes that we get are in the form of an array. The first part of the array contains the index number of the cell note, followed by the cell note content.
- Store the note in an array.
- Print the note
- Get the cell next to the cell note
- Using the offset function set the note in the cell
Step 4: Check the Output
We are done with the code, go ahead and save it. Select the correct function (getCellNote) as shown below and run the program.
On successful execution, you will see the following output:
Here you can see that the cell note has been inserted next to the original cell.
Using Google Apps Script GetDataRange Function in Google Sheets to Extract Cell Notes: A Summary
We saw how you can extract cell notes into another column in Google Sheets using the Google Apps Script getdatarange function. To sum up :
- Accessed the Spreadsheet followed by the Active sheet
- Got the Data Range
- Got the notes from the specified range
- Used two for loops to check if the note is not empty
- Stored the note (or notes) in an array
- Got the cell next to the cell note
- Set the note next to the original cell
I hope you have understood how to Extract Cell notes into another column using the Apps Script getdatarange function.