<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nibesh Khadka</title>
    <description>The latest articles on DEV Community by Nibesh Khadka (@kcl).</description>
    <link>https://dev.to/kcl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F608864%2Fa011de04-2aca-4825-acbc-07b0a62746ab.png</url>
      <title>DEV Community: Nibesh Khadka</title>
      <link>https://dev.to/kcl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kcl"/>
    <language>en</language>
    <item>
      <title>How to Integrate ChatGpt Into Google Sheets With Apps Script?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Mon, 25 Sep 2023 00:19:30 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-integrate-chatgpt-into-google-sheets-with-apps-script-2f5h</link>
      <guid>https://dev.to/kcl/how-to-integrate-chatgpt-into-google-sheets-with-apps-script-2f5h</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/DlcJv97TZhE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>javascript</category>
      <category>chatgpt</category>
      <category>spreadsheets</category>
    </item>
    <item>
      <title>Find the Last Row In Google Sheets With Google Apps Script!</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Fri, 09 Jun 2023 18:15:00 +0000</pubDate>
      <link>https://dev.to/kcl/find-the-last-row-in-google-sheets-with-google-apps-script-gl8</link>
      <guid>https://dev.to/kcl/find-the-last-row-in-google-sheets-with-google-apps-script-gl8</guid>
      <description>&lt;p&gt;Hello!, I wrote a blog on finding the &lt;a href="https://dev.to/kcl/how-to-find-the-last-row-in-a-column-with-google-apps-script-3npa"&gt;last non-empty rows&lt;/a&gt; a couple of months ago. Since then, I have found a better, faster, and easier method, which works in most cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find the Last Row &amp;amp; Column
&lt;/h2&gt;

&lt;p&gt;You can copy and paste one of the following functions as per your needs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;FindLastRowNColBoundScript()&lt;/code&gt;, is meant for a bound script, is very easy to implement, and works on the currently active worksheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;FindLastRowNColIndependentScript()&lt;/code&gt; should be used with an independent script. The given code is very simple. You can modify this function and pass variables such as ID and Worksheet names as parameters to make this function more dynamic.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Function should be used for bound script.
 * Function use getDataRange().getValues() method to 
 * find lastRow and LastColumn of that Spreadhseet.
 */
function findLastRowNColBoundScript() {
  const sheet = SpreadsheetApp.getActiveSheet();

  const data = sheet.getDataRange().getValues();
  const lastRow = data.length;
  const lastCol = data[0].length;

  console.log(lastRow);
  console.log(lastCol);

  return [lastRow, lastCol];
}

/**
 * Function should be used for independent script.
 * Function use getDataRange().getValues() method to 
 * find lastRow and LastColumn of that Spreadhseet
 */
function findLastRowNColIndependentScript() {
  const ss = SpreadsheetApp.openById("&amp;lt;Your Spreadsheet's ID&amp;gt;");
  const sheet = ss.getSheetByName("&amp;lt;Name of the worksheet&amp;gt;");

  const data = sheet.getDataRange().getValues();
  const lastRow = data.length;
  const lastCol = data[0].length;

  console.log(lastRow);
  console.log(lastCol);

  return [lastRow, lastCol];
}


/**
 * This script is for finding last non empty rows and columns in a spreadsheet. 
 * This works in most cases but not in some cases such as columns with checkboxes
 * It is created in such a way that it only works with bound script.
 *
 * Created by: Nibesh Khadka.
 * linkedin: https://www.linkedin.com/in/nibesh-khadka/
 * website: https://nibeshkhadka.com
 */

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This strategy of using &lt;a href="https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getdatarange"&gt;DataRange()&lt;/a&gt; to find the last row and columns works in most cases but few such as columns filled with checkboxes on their entire rows.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;My name is Nibesh Khadka, and as a freelance automation expert, I specialize in automating Google products with Apps Script. If you need my services let me &lt;a href="https://nibeshkhadka.com/contact/"&gt;know&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifgfep9koji3bhm5egdt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifgfep9koji3bhm5egdt.png" alt="Like and Share the Blog" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>spreadsheets</category>
      <category>automation</category>
      <category>findlastrow</category>
    </item>
    <item>
      <title>How To Delete Empty Rows and Columns In Google Sheets?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Tue, 02 May 2023 20:15:00 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-delete-empty-rows-and-columns-in-google-sheets-3gph</link>
      <guid>https://dev.to/kcl/how-to-delete-empty-rows-and-columns-in-google-sheets-3gph</guid>
      <description>&lt;p&gt;Welcome to this very short daily blog where I give a very simple script to automate Google Products. In this chapter, we'll custom menu that'll delete empty rows and columns in current active spreadsheets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delete Empty/Extra Rows and Column
&lt;/h2&gt;

&lt;p&gt;The following bound script will do three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a custom menu in your spreadsheets tabs with the title Custom Menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After you call to select the custom menu, It will check all the extra rows and columns after the last rows and columns with data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then delete all those extra rows and columns.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;function deleteExteriorRowsNColumns() {&lt;br&gt;
  // get sheets and data&lt;br&gt;
  const sheet = SpreadsheetApp.getActiveSheet();&lt;br&gt;
  const data = sheet.getDataRange().getValues();&lt;/p&gt;

&lt;p&gt;// determine last row and column&lt;br&gt;
  const lastRow = data.length;&lt;br&gt;
  const lastCol = Math.max(...data.map((arr) =&amp;gt; arr.length));&lt;/p&gt;

&lt;p&gt;// get maximum rows and columns sheets&lt;br&gt;
  const maxRows = sheet.getMaxRows();&lt;br&gt;
  const maxCols = sheet.getMaxColumns();&lt;/p&gt;

&lt;p&gt;// only remove rows and columns if there are empty rows or columns beyond last row and columns&lt;br&gt;
  if (maxRows &amp;gt; lastRow) {&lt;br&gt;
    sheet.deleteRows(lastRow + 1, maxRows - lastRow);&lt;br&gt;
  }&lt;br&gt;
  if (maxCols &amp;gt; lastCol) {&lt;br&gt;
    sheet.deleteColumns(lastCol + 1, maxCols - lastCol);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;/**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OnOpen trigger that creates menu&lt;/li&gt;
&lt;li&gt;@param {Dictionary} e
*/
function onOpen(e) {
createCustomMenu();
}&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;/**&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Menu creates menu UI in spreadsheet.
*/
function createCustomMenu() {
let menu = SpreadsheetApp.getUi().createMenu("Custom Menu"); &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;menu.addItem("Delete Empty Rows and Columns", "deleteExteriorRowsNColumns");&lt;br&gt;
  menu.addToUi();&lt;br&gt;
}&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  How To Add Apps Script Code To a Spreadsheet?&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;If you don't know how to add this script to your sheet then, then just click the Extensions tab and then Apps Script as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmfmov053a07woa3jqkyl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmfmov053a07woa3jqkyl.png" alt="Open Script Menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, similar to the &lt;a href="https://dev.to/kcl/series/19218"&gt;previous blogs&lt;/a&gt;, you can now just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the document. Where you'll see the custom menu as shown below&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And execute the function from the custom menu as shown in the image below.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwj5yx58pvs8g5mgs4h2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwj5yx58pvs8g5mgs4h2.png" alt="Custom Menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3t4vfufxko945sgmf76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3t4vfufxko945sgmf76.png" alt="Delete Empty Rows and Coumn Results"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;My name is Nibesh Khadka, and as a freelance automation expert, I specialize in automating Google products with Apps Script. So let's get started! If you need my services let me &lt;a href="https://nibeshkhadka.com/contact/" rel="noopener noreferrer"&gt;know&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>googlesheets</category>
      <category>spreadsheets</category>
      <category>deleteemptyrows</category>
    </item>
    <item>
      <title>Use This Script to Separate The First and Last Names in Spreadsheets?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Sat, 29 Apr 2023 20:15:00 +0000</pubDate>
      <link>https://dev.to/kcl/how-separate-the-first-and-last-names-in-spreadsheets-3p5o</link>
      <guid>https://dev.to/kcl/how-separate-the-first-and-last-names-in-spreadsheets-3p5o</guid>
      <description>&lt;p&gt;Would you like to separate the column in your spreadsheet that consists of the full names of people into first and last names? Well then stick this very simple script to your spreadsheets apps script editor and you'll be able to do just that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split The Selected Column
&lt;/h2&gt;

&lt;p&gt;The following &lt;a href="https://developers.google.com/apps-script/guides/bound"&gt;bound&lt;/a&gt; script will do three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a custom menu in your spreadsheets tabs with the title Custom Menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After you call select the custom menu, It will check the cell you've selected to split into. The script won't work if you don't select a cell in the right column.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Separate the whole column into two columns, with the first value in the first column and the second(&amp;amp; rest if there are any) in the new column.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function splitName() {
  // get sheet and data
  const sheet = SpreadsheetApp.getActiveSheet();
  // get selected row
  const activeColIndex = sheet.getActiveRange().getColumn();

  const data = sheet.getDataRange().getValues();
  const lastRow = data.length;

  sheet.getRange(1,activeColIndex,lastRow,1).splitTextToColumns();

}

// if you're new and only want this feature the use this code
/**
 * OnOpen trigger that creates menu
 * @param {Dictionary} e
 */
function onOpen(e) {
  createCustomMenu();
}

/**
 * Menu creates menu UI in spreadsheet.
 */
function createCustomMenu() {
  let menu = SpreadsheetApp.getUi().createMenu("Custom Menu"); // Or DocumentApp or SlidesApp or FormApp.

  menu.addItem("Split Names", "splitName");
  menu.addToUi();
}

/**
 * Code By Nibesh Khadka.
 * I am freelance and Google Workspace Automation Expert.
 * You can find me in:
 * https://linkedin.com/in/nibesh-khadka
 * https://nibeshkhadka.com
 * me@nibeshkhadka.com
 */

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How To Add Apps Script Code To a Spreadsheet?
&lt;/h3&gt;

&lt;p&gt;If you don't know how to add this script to your sheet then, then just click the Extensions tab and then Apps Script as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3pqipnkw8dr7aze4155.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp3pqipnkw8dr7aze4155.png" alt="Open Scrpit Editor" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, similar to the previous &lt;a href="https://dev.to/kcl/series/19218"&gt;blogs&lt;/a&gt;, you can now just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the document. Where you'll see the custom menu as shown below&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And execute the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Executing The Function
&lt;/h3&gt;

&lt;p&gt;Here are a few images to guide what the operation will look like in your docs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fggpeq29lre1s58cv2pfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fggpeq29lre1s58cv2pfc.png" alt="Custom Menu" width="800" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2fikqnusvmb2on72wvok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2fikqnusvmb2on72wvok.png" alt="Before and After Name Split" width="564" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;My name is Nibesh Khadka, and as a freelance automation expert, I specialize in automating Google products with Apps Script. So let's get started! If you need my services let me &lt;a href="https://nibeshkhadka.com/contact/"&gt;know&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3za0u95xedbxtn1ll4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3za0u95xedbxtn1ll4n.png" alt="Like, Share and Follow Khadka's Coding Lounge" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>googlesheets</category>
      <category>automation</category>
      <category>spreadsheets</category>
    </item>
    <item>
      <title>How to Easily Copy a Column From One Sheet to Another in Google Sheets?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Wed, 26 Apr 2023 18:18:11 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-easily-copy-a-column-from-one-sheet-to-another-in-google-sheets-2eio</link>
      <guid>https://dev.to/kcl/how-to-easily-copy-a-column-from-one-sheet-to-another-in-google-sheets-2eio</guid>
      <description>&lt;p&gt;In this blog, I will be sharing a script that allows you to easily select a column in a Google Sheets spreadsheet and copy it to another spreadsheet while ensuring that the values are aligned in the same rows. Whether you're a Google Apps Script Developer or just someone looking to streamline their workflow, this script will be a helpful tool for you.&lt;/p&gt;

&lt;p&gt;This is Nibesh Khadka. I am a freelance Google Apps Script Developer and Content Creator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Referencing Columns Before Copying
&lt;/h2&gt;

&lt;p&gt;Copying a column from one sheet to another can be challenging if we don't have a unique column as a reference to put the values in the correct column. We can use columns like ID, Email, or any other column that exists in both sheets as a reference. In this article, we'll create a spreadsheet with two sheets and use the "ID" column as a reference to copy the "Name" column from Sheet1 to Sheet2.&lt;/p&gt;

&lt;p&gt;You can just download and use &lt;a href="https://docs.google.com/spreadsheets/d/1pPQwcNFue4635rYZDdIaTbK0iV4OV_MQ77BFMs6-SCM/edit"&gt;this&lt;/a&gt; sheet or create your own. You can either follow the steps or download the complete code from the git &lt;a href="https://github.com/nibukdk/DailyBlogChallenge/tree/master/CopyColumnData"&gt;repository&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Script Editor
&lt;/h2&gt;

&lt;p&gt;Now this is the bound script. So, open the spreadsheet you want to use for this project and open the script editor from there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F71warh9pvbhxy9c4x1iy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F71warh9pvbhxy9c4x1iy.png" alt="Open Script Editor" width="274" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML Form
&lt;/h2&gt;

&lt;p&gt;For this project, unlike in the previous one, we'll be using Custom Dialog Boxes with HTML instead of UI prompts because we'll need multiple input boxes for this project.&lt;/p&gt;

&lt;p&gt;Create a new HTML file in your script editor. Then copy and paste the following codes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;base target="_top"&amp;gt;
  &amp;lt;!-- &amp;lt;style&amp;gt;
    .targetColumnInfo {
      color: grey;
      font-size: 10px;
    }
  &amp;lt;/style&amp;gt; --&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;form onsubmit="formSubmitHandler(event)"&amp;gt;
    &amp;lt;h2&amp;gt;Source Sheet&amp;lt;/h2&amp;gt;
    &amp;lt;label for="sourceSheet"&amp;gt;Source Sheet Name:&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="text" id="sourceSheet" name="sourceSheet"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="referenceColumn"&amp;gt;Reference Column Name&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="text" id="referenceColumn" name="referenceColumn"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="sourceColumn"&amp;gt;Source Column To Copy From:&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="text" id="sourceColumn" name="sourceColumn"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;hr&amp;gt;
    &amp;lt;h2&amp;gt;Target Sheet&amp;lt;/h2&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="targetSheet"&amp;gt;Target Sheet Name:&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="text" id="targetSheet" name="targetSheet"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="targetReferenceColumn"&amp;gt;Reference Column Name&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="text" id="targetReferenceColumn" name="targetReferenceColumn"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;label for="targetColumn"&amp;gt;Target Column To Copy To:*&amp;lt;/label&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;input type="text" id="targetColumn" name="targetColumn"&amp;gt;&amp;lt;br&amp;gt;
    &amp;lt;!-- &amp;lt;p class="targetColumnInfo"&amp;gt;*Leave Last Input Empty to create new target column&amp;lt;/p&amp;gt; --&amp;gt;

    &amp;lt;input type="submit" value="Submit" /&amp;gt;

  &amp;lt;/form&amp;gt;

  &amp;lt;script&amp;gt;
    function formSubmitHandler(event) {

      const sourceSheet = event.target['sourceSheet'].value;
      const referenceColumn = event.target['referenceColumn'].value;
      const sourceColumn = event.target['sourceColumn'].value;
      const targetSheet = event.target['targetSheet'].value;
      const targetReferenceColumn = event.target['targetReferenceColumn'].value;
      const targetColumn = event.target['targetColumn'].value ?? "";
      const data = [sourceSheet, referenceColumn, sourceColumn, targetSheet, targetReferenceColumn, targetColumn];

      // call server side function
     google.script.run.withSuccessHandler(closeDialog).setTargetColumns(data);

      event.preventDefault();

    }

    function closeDialog() { google.script.host.close() }
  &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two &lt;a href="https://developers.google.com/apps-script/guides/html/communication#script_runners"&gt;script runners&lt;/a&gt; to notice here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.google.com/apps-script/guides/html/communication#success_handlers"&gt;withSuccessHandler()&lt;/a&gt; is used to link the function in the form in the front-end to the function in the backend(script) code during operation success, in this case, setTargetColumns() is the backend function we're using.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.google.com/apps-script/guides/html/communication#closing_dialogs_and_sidebars_in"&gt;close()&lt;/a&gt; which is used to close the dialog box. We are using it with withSuccessHandler() to call the backend and then close the dialog box.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When rendered the Form looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fll3tcijkaynjhbvxsze8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fll3tcijkaynjhbvxsze8.png" alt="Copy Column Form" width="398" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Feel free to style the HTML Form to make it more beautiful.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this HTML form you'll have to provide six pieces of information:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The name of the Source Worksheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name of the Reference Column in the source sheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name of the Source Column in the source sheet whose value is to be copied.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name of the Target Worksheet where the value is to be copied.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name of the Reference Column in the target sheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The name of the Target Column in the target sheet, that will hold the copied value.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Copy Column to Different Sheet
&lt;/h2&gt;

&lt;p&gt;Now let's write the script to copy the values from one column to another.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function renderForm() {
  const html = HtmlService.createHtmlOutputFromFile('form')
    .setWidth(400)
    .setHeight(600);// play with dimension to fit your need
  SpreadsheetApp.getUi() 
    .showModalDialog(html, "Copy Column With Reference");
}

//["Sheet1", "ID", "Name", "Sheet2", "ID", "Name"]
function setTargetColumns(data) {
  try {
    const sourceSheetName = data[0];
    const referenceColumnName = data[1];
    const sourceColumnName = data[2];
    const targetSheetName = data[3];
    const targetReferenceColumnName = data[4];
    const targetColumnName = data[5];

    // get sheet and data
    const sheet = SpreadsheetApp.getActiveSpreadsheet();
    const sourceSheet = sheet.getSheetByName(sourceSheetName);

    const sourceSheetData = sourceSheet.getDataRange().getValues();
    const sourceSheetLastRow = sourceSheetData.length;
    const sourceSheetLastColumn = sourceSheetData[0].length;
    // get header column of source sheet
    const sourceSheetHeader = sourceSheet.getRange(1, 1, 1, sourceSheetLastColumn).getValues().flat();

    // find the index of the given column names
    const referenceColumnIndex = sourceSheetHeader.indexOf(referenceColumnName.trim());
    if (referenceColumnIndex === -1) throw "Reference Column Not Found";

    const sourceColumnIndex = sourceSheetHeader.indexOf(sourceColumnName.trim());
    if (sourceColumnIndex === -1) throw "Source Column Not Found"; // if the name is not found then throw error

    const sourceSheetData2 = [sourceSheet.getRange(2, referenceColumnIndex + 1, sourceSheetLastRow, 1).getValues().flat(), sourceSheet.getRange(2, sourceColumnIndex + 1, sourceSheetLastRow, 1).getValues().flat()]


    const targetSheet = sheet.getSheetByName(targetSheetName);
    const targetSheetData = targetSheet.getDataRange().getValues();
    const targetSheetLastRow = targetSheetData.length;


    const targetReferenceColumnIndex = sourceSheetHeader.indexOf(targetReferenceColumnName.trim());
    if (targetReferenceColumnIndex === -1) throw "Target Sheets Reference Column Not Found";

    const targetColumnIndex = sourceSheetHeader.indexOf(targetColumnName.trim());
    if (targetColumnIndex === -1) throw "Target Sheet's Target Column Not Found";

    const targetSheetRefData = targetSheet.getRange(2, targetReferenceColumnIndex + 1, targetSheetLastRow - 1, 1).getValues().flat();
    const targetSheetColData = targetSheet.getRange(2, targetColumnIndex + 1, targetSheetLastRow - 1, 1).getValues();


    for (let i = 0; i &amp;lt; sourceSheetData2[0].length; i++) {
      for (let j = 0; j &amp;lt; targetSheetRefData.length; j++) {
        if (targetSheetRefData[j] === sourceSheetData2[0][i]) {
          targetSheetColData[j] = [sourceSheetData2[1][i]];
          break;
        }
        continue;
      }
    }
    // set new values 
    targetSheet.getRange(2, targetColumnIndex + 1, targetSheetLastRow - 1, 1).setValues(targetSheetColData);

  } catch (e) {
    // alert error
    SpreadsheetApp.getUi().alert(`Error: ${e}`)
  }
}


/**
 * Menu creates menu UI in the document it's bound to.
 */
function createCustomMenu() {
  const menu = SpreadsheetApp.getUi().createMenu("Copy Columns");

  menu.addItem("Copy Column", "renderForm");
  menu.addToUi();
}


/**
 * OnOpen trigger that creates menu
 * @param {Dictionary} e
 */
function onOpen(e) {
  createCustomMenu();
}

/**
 * This script is for safely and accurately copying one column to 
 * another column in two sheets while properly aliging with other
 * rows.
 * It is created in such a way that it only works with bound script.
 *
 * Created by: Nibesh Khadka.
 * linkedin: https://www.linkedin.com/in/nibesh-khadka/
 * website: https://nibeshkhadka.com
 */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, similar to the &lt;a href="https://dev.to/kcl/how-to-insert-multiple-rows-in-google-sheets-with-apps-script-4pd8"&gt;previous blogs&lt;/a&gt;, you can now just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the spreadsheet. Where you'll see the custom menu as shown below&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And execute the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this, you'll see a menu like the image below in the spreadsheet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzpsd47m31n62a0azhxt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flzpsd47m31n62a0azhxt.png" alt="Copy Column Custom Menu" width="800" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Error
&lt;/h2&gt;

&lt;p&gt;In case you leave any input box empty or you gave the wrong names to the boxes, you'll see the error alert like the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpz1tn92cv9wljxaj6339.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpz1tn92cv9wljxaj6339.png" alt="Empty Input Error" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;My name is Nibesh Khadka, and as a freelance automation expert, I specialize in automating Google products with Apps Script. So let's get started! If you need my services let me &lt;a href="https://nibeshkhadka.com/contact/"&gt;know&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>googlesheets</category>
      <category>datamanagement</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to check word count in Google Docs?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Tue, 25 Apr 2023 06:58:53 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-see-how-many-words-you-have-on-google-docs-4pfh</link>
      <guid>https://dev.to/kcl/how-to-see-how-many-words-you-have-on-google-docs-4pfh</guid>
      <description>&lt;p&gt;Are you tired of manually counting the number of words in your Google Docs while working on your blog or article? Well, fret not, as I have got you covered with a simple yet effective solution. In this tutorial series on Apps Script, I will walk you through a step-by-step guide on how to create a script that can read your Google Docs and return the exact word count of your document, making your life easier and your writing process more efficient. So, let's dive in and learn how to see how many words you have on Google Docs!&lt;/p&gt;

&lt;p&gt;Welcome to the apps script tutorial series, where I, Nibesh Khadka, provide short and sweet scripts and teach a few things along the way to make our life less miserable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Google Docs Word Counter Script
&lt;/h2&gt;

&lt;p&gt;The given script will do just exactly what was promised earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Word Counter is A simple script to count number of words written in a google docs with apps script.
 */
function wordCounter() {
  let doc = DocumentApp.getActiveDocument();
  let data = doc.getText();

  let processedData = data.split("\n").filter(String).map(item =&amp;gt; item.split(" ")).flat().filter(String);

  let wordCount = processedData.length;
  // now alet the word count
  DocumentApp.getUi().alert(`You have ${wordCount} words in this document.`)
}


/**
 * Menu creates menu UI in the document it's bound to.
 */
function createCustomMenu() {
  let menu = DocumentApp.getUi().createMenu("Count Number of Words"); // Or DocumentApp or SlidesApp or FormApp.

  menu.addItem("Word Counter", "wordCounter");
  menu.addToUi();
}


/**
 * OnOpen trigger that creates menu
 * @param {Dictionary} e
 */
function onOpen(e) {
  createCustomMenu();
}

/**
 * Word Counter is a script to count number of words written in Google Docs with Google Apps Script. 
 * It is created in such a way that it only works with bound script.
 * 
 * Created by: Nibesh Khadka.
 * linkedin: https://www.linkedin.com/in/nibesh-khadka/
 * website: https://nibeshkhadka.com
 */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use Google Apps Script For Non-Coders?
&lt;/h2&gt;

&lt;p&gt;This is a &lt;a href="https://developers.google.com/apps-script/guides/bound"&gt;container-bound script&lt;/a&gt; i.e the script has to be attached to a file, in this case, a Google Docs. So, first, you'll have to open the document in which you'd want to count the number of words.&lt;/p&gt;

&lt;p&gt;There just click the Extensions tab and then Apps Script as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvtbh4ko6m6178jxyi8h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxvtbh4ko6m6178jxyi8h.png" alt="Open Script Editor" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There, on code.gs file, just replace those codes with the codes above.&lt;/p&gt;

&lt;p&gt;Now, similar to the &lt;a href="https://dev.to/kcl/series/19218"&gt;previous blogs&lt;/a&gt;, you can now just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the document. Where you'll see the custom menu as shown below&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And execute the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Executing The Function
&lt;/h2&gt;

&lt;p&gt;Here are a few images to guide what the operation will look like in your docs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqn6wr6iagow9l7rzrms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqn6wr6iagow9l7rzrms.png" alt="Word Counter Menu" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdatrvpvxjtbcqy8o43s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqdatrvpvxjtbcqy8o43s.png" alt="Number Of Words In Google Docs" width="777" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;My name is Nibesh Khadka, and as a freelance automation expert, I specialize in automating Google products with Apps Script. So let's get started! If you need my services &lt;a href="https://nibeshkhadka.com/contact"&gt;let me know&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqjsf9pveeq1oc6atsqu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqjsf9pveeq1oc6atsqu.png" alt="Like, Share and Follow Khadka's Coding Lounge" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>googledocs</category>
      <category>countwords</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to Insert Multiple Rows in Google Sheets with Apps Script?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Mon, 24 Apr 2023 10:35:17 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-insert-multiple-rows-in-google-sheets-with-apps-script-4pd8</link>
      <guid>https://dev.to/kcl/how-to-insert-multiple-rows-in-google-sheets-with-apps-script-4pd8</guid>
      <description>&lt;p&gt;Hello and welcome to our blog series on automating Google Sheets with Apps Script. In this tutorial, we will guide you on how to insert multiple rows in Google Sheets using a simple script. We'll explore how to use UiApp to create a custom user interface for inserting rows in Google Sheets and how to add dynamic row insertion features to the menu.&lt;/p&gt;

&lt;p&gt;Whether you are a beginner or an experienced user, this guide will provide you with step-by-step instructions to help you streamline your workflow and save time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Dynamic Row Insertion Features with UiApp in Google Sheet
&lt;/h2&gt;

&lt;p&gt;Google Sheets is a powerful tool for managing data, but sometimes users need to insert multiple rows at once. To make this process more efficient, we can use the &lt;a href="https://developers.google.com/apps-script/reference/base/ui"&gt;UiApp&lt;/a&gt; class from Apps Script. With UiApp, we can create a simple user interface that allows the user to specify the number of rows they want to insert. However, UiApp has its limitations, such as not being able to create dynamic input for inserting rows above or below. To overcome this limitation, we can add two functions to the menu that will insert rows above or below after asking for the number of rows to enter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing Functions to Insert Multiple Rows in Google Sheets
&lt;/h2&gt;

&lt;p&gt;Now, on your spreadsheet, click the Extensions tab and then Apps Script as shown in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcehmgkqm1x5npw0b4w48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcehmgkqm1x5npw0b4w48.png" alt="Open Script Editor" width="668" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you're continuing on the &lt;a href="https://dev.to/kcl/removing-duplicates-in-google-sheets-a-guide-for-non-coders-4jng"&gt;previous blog&lt;/a&gt;, then create a new script file with a preferred name, I'll call it insert_multiple_rows.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There copy and paste the following codes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function insertMultipleRowsAbove() {
  // get sheet and data
  let sheet = SpreadsheetApp.getActiveSheet();
  // get selected row
  let activeRowIndex = sheet.getActiveRange().getRowIndex();
  // get ui
  let ui = SpreadsheetApp.getUi();
  // ask for number of rows to insert
  let response = ui.prompt(`Selected row: ${activeRowIndex}.

  Enter the number of rows you want to insert above the selected row:`);

  // Process the user's response.
  if (response.getSelectedButton() == ui.Button.OK) {
    let numRows = Number(response.getResponseText());
    sheet.insertRowsBefore(activeRowIndex, numRows);
    ui.alert(`${numRows} has been inserted above the ${activeRowIndex} row.`);

  } else {
    ui.alert(`Please press the ok button after you enter the number.`);
  }

}

function insertMultipleRowsBelow() {
  // get sheet and data
  let sheet = SpreadsheetApp.getActiveSheet();
  // get selected row
  let activeRowIndex = sheet.getActiveRange().getRowIndex();
  // get ui
  let ui = SpreadsheetApp.getUi();
  // ask for number of rows to insert
  let response = ui.prompt(`Selected row: ${activeRowIndex}.

  Enter the number of rows you want to insert below the selected row:`);

  // Process the user's response.
  if (response.getSelectedButton() == ui.Button.OK) {
    let numRows = Number(response.getResponseText());
    sheet.insertRowsAfter(activeRowIndex, numRows);
    ui.alert(`${numRows} has been inserted after the ${activeRowIndex} row.`);

  } else {
    ui.alert(`Please press the ok button after you enter the number.`);
  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we created two functions - &lt;strong&gt;insertMultipleRowsAbove()&lt;/strong&gt; and &lt;strong&gt;insertMultipleRowsBelow()&lt;/strong&gt;. Both functions perform almost the same task of asking the user for the number of rows to insert and then inserting them either above or below the selected row index. The only difference between the two functions is the method used to insert the rows - &lt;a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet#insertrowsbeforebeforeposition,-howmany"&gt;insertRowsBefore()&lt;/a&gt; and &lt;a href="https://developers.google.com/apps-script/reference/spreadsheet/sheet#insertrowsafterafterposition,-howmany"&gt;insertRowsAfter()&lt;/a&gt; respectively. These functions will come in handy when you need to insert multiple rows at once, saving you time and effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding the Insert Multiple Rows Function to the Custom Menu
&lt;/h3&gt;

&lt;p&gt;Now we'll add these two functions to our menu.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Again if you're continuing to the &lt;a href="https://dev.to/kcl/removing-duplicates-in-google-sheets-a-guide-for-non-coders-4jng"&gt;previous blog&lt;/a&gt;, then locate the createCustomMenu() function in your files and edit the codes there. And only add one of the following functions in your files per your needs.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// if you're new and only want this feature the use this code
/**
 * OnOpen trigger that creates menu
 * @param {Dictionary} e
 */
function onOpen(e) {
  createCustomMenu();
}

/**
 * Menu creates menu UI in spreadsheet.
 */
function createCustomMenu() {
  let menu = SpreadsheetApp.getUi().createMenu("Insert Multiple Rows"); // Or DocumentApp or SlidesApp or FormApp.

  menu.addItem("Insert Multiple Rows Above", "insertMultipleRowsAbove");
  menu.addItem("Insert Multiple Rows Below", "insertMultipleRowsBelow");
  menu.addToUi();
}
//======================================================//
// if you're continuing the previous blog then add this

/**
 * Menu creates menu UI in spreadsheet.
 */
function createCustomMenu() {
  let menu = SpreadsheetApp.getUi().createMenu("Highlight Duplicate Rows"); // Or DocumentApp or SlidesApp or FormApp.

  menu.addItem("Highlight Duplicate Row", "colorDuplicateRows");
  menu.addItem("Delete Duplicate Row", "deleteDuplicateRows");
  menu.addItem("Reset Colors", "colorReset");
  menu.addItem("Insert Multiple Rows Above", "insertMultipleRowsAbove");
  menu.addItem("Insert Multiple Rows Below", "insertMultipleRowsBelow");
  menu.addToUi();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here, similar to the previous blogs, you can now just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the spreadsheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And execute the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You'll see the respective menus and titles depending on the codes you choose above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Executing The Function
&lt;/h2&gt;

&lt;p&gt;Here are a few images to guide what the operation will look like in your sheet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1rfwet90baqfsda4vrx0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1rfwet90baqfsda4vrx0.png" alt="Menu" width="666" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbibccf8w34i6iw689d41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbibccf8w34i6iw689d41.png" alt="Insert Row Input Prompt" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpl89tkvbay7tpg20ao5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpl89tkvbay7tpg20ao5q.png" alt="Insert Rows Sucess Alert" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;My name is Nibesh Khadka, and as a freelance automation expert, I specialize in automating Google products with Apps Script. So let's get started! If you need my services let me &lt;a href="https://nibeshkhadka.com/contact/"&gt;know&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdsm2dtc5y1auuibk9in.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdsm2dtc5y1auuibk9in.png" alt="Like, Share and Follow Khadka's Coding Lounge" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googlesheets</category>
      <category>spreadsheets</category>
      <category>googleappsscript</category>
      <category>automation</category>
    </item>
    <item>
      <title>Removing Duplicates in Google Sheets: A Guide for Non-coders</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Thu, 16 Mar 2023 06:35:24 +0000</pubDate>
      <link>https://dev.to/kcl/removing-duplicates-in-google-sheets-a-guide-for-non-coders-4jng</link>
      <guid>https://dev.to/kcl/removing-duplicates-in-google-sheets-a-guide-for-non-coders-4jng</guid>
      <description>&lt;p&gt;&lt;em&gt;Ugh.., I have so many duplicate rows in my spreadsheet.&lt;/em&gt; Well so do many other people. With the script in this article, you can introduce a menu button that lets you delete duplicate rows in your spreadsheet.&lt;/p&gt;

&lt;p&gt;This blog is the second part of the blog I published a few days ago: “&lt;a href="https://dev.to/kcl/how-to-highlight-duplicate-rows-in-google-sheets-19mo"&gt;How to Highlight Duplicate Rows in Google Sheets?&lt;/a&gt;”. There I provided a simple script to highlight duplicate rows. This script will extend that script to delete those duplicate rows.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FXo3Snwpf84"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  For Non-Coders
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqzr7kwkkp0cdwqrx3wvp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqzr7kwkkp0cdwqrx3wvp.png" alt="Open Script Editor" width="668" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re not a coder and don’t wanna be bothered with an explanation then follow this step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Script editor. On your spreadsheet click the &lt;strong&gt;Extensions&lt;/strong&gt; tab and then &lt;strong&gt;Apps Script&lt;/strong&gt; as shown in the image above.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove all the codes in Code.gs. Then copy and paste the code from the Full Code section in this blog.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save and then reload the spreadsheet. Now, reopen the Apps script as instructed in step 1 (&lt;em&gt;Sometimes the script doesn't work without saving and reloading&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;If you’re already using the previous script then you can just copy and paste this script over the previous one.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Full Code
&lt;/h2&gt;

&lt;p&gt;Here’s the full script for this blog including the previous blog’s code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
/**
 *The colorDuplicateRows() colors the duplicate rows.
 *Each unique rows and its duplicates are highlighted with different color
 */
function colorDuplicateRows() {
  // get sheet and data
  let sheet = SpreadsheetApp.getActiveSheet();
  let data = sheet.getDataRange().getValues();

  // find lastCol
  let lastCol = Math.max(...data.map((arr) =&amp;gt; arr.length));

  // convert nested arrays to string
  data = data.map((arr) =&amp;gt; arr.join(""));
  // find unique ones among arrays
  let uniqueRows = [...new Set(data)].filter(String);
  // create unique color for each unique arr
  let uniqueColor = {};
  uniqueRows.forEach((val) =&amp;gt; (uniqueColor[val] = getRandomUniqueColor()));

  // console.log(uniqueColor);
  // find duplicate row for each item
  let duplicateRows = data
    .map((x, i) =&amp;gt; (isDuplicateRow(x, data) ? i + 1 : ""))
    .filter(String);
  // console.log(duplicateRows);

  // now reset color before highlighting duplicate rows
  colorReset();

  duplicateRows.forEach((rowNum) =&amp;gt; {
    for (let i = 0; i &amp;lt; uniqueRows.length; i++) {
      //console.log(range.getValues())
      // compare each item with uniqe items and assing color accordingly
      if (
        sheet.getRange(rowNum, 1, 1, lastCol).getValues().flat().join("") ===
        uniqueRows[i]
      ) {
        sheet
          .getRange(rowNum, 1, 1, lastCol)
          .setBackground(uniqueColor[uniqueRows[i]]);
      }
    }
  });
}

/**
 * Function takes two items: row and arr.
 * The parameter "row" is a string to be compared to items in array "arr".
 * Inspired from https://stackoverflow.com/a/68424642/6163929
 * @param {String} row
 * @param {Array&amp;lt;String&amp;gt;} arr
 * @returns {Boolean}
 */
function isDuplicateRow(row, arr) {
  return row === "" ? false : arr.indexOf(row) != arr.lastIndexOf(row);
}

/**
 * Menu creates menu UI in spreadsheet.
 */
function createCustomMenu() {
  let menu = SpreadsheetApp.getUi().createMenu("Highlight Duplicate Rows"); // Or DocumentApp or SlidesApp or FormApp.

  menu.addItem("Highlight Duplicate Row", "colorDuplicateRows");
  menu.addItem("Delete Duplicate Row", "deleteDuplicateRows");
  menu.addItem("Reset Colors", "colorReset");
  menu.addToUi();
}

/**
 * OnOpen trigger that creates menu
 * @param {Dictionary} e
 */
function onOpen(e) {
  createCustomMenu();
}

/**
 * ColorReset is used to reset bg color of spreadsheet to its original color.
 */
function colorReset() {
  let sheet = SpreadsheetApp.getActiveSheet();
  sheet.getDataRange().setBackground("");
}

/**
 * Function creates a unique random color as hashcode.
 * @returns {String}
 */
function getRandomUniqueColor() {
  // thanks to function https://dev.to/rajnishkatharotiya/generate-unique-color-code-in-javascript-3h06
  let n = (Math.random() * 0xfffff * 1000000).toString(16);
  return "#" + n.slice(0, 6);
}


/**
 *The deleteDuplicateRows() funciton deleted the duplicate 
 *rows in current active spreadsheet.
 */
function deleteDuplicateRows() {
  // get sheet and data
  let sheet = SpreadsheetApp.getActiveSheet();
  let data = sheet.getDataRange().getValues();



  // convert nested arrays to string
  data = data.map((arr) =&amp;gt; arr.join(";"));
  // find unique ones among arrays
  let uniqueRows = [...new Set(data)].filter(String);
  // convert the values from string to qrray again
  let newData = uniqueRows.map(itemStr =&amp;gt; itemStr.split(";"));

  // find last row and col for new range.
  let newLastRow = newData.length;
  let newLastCol = Math.max(...newData.map((arr) =&amp;gt; arr.length));

  // reset previous colors if the highlight function is used
  colorReset();


  // clear previous contents to save only unique values
  sheet.clearContents();
  // set new values
  sheet.getRange(1, 1, newLastRow, newLastCol).setValues(newData);

}


/**
 * Code By Nibesh Khadka.
 * I am freelance and Google Workspace Automation Expert.
 * You can find me in:
 * https://linkedin.com/in/nibesh-khadka
 * https://nibeshkhadka.com
 * me@nibeshkhadka.com
 */

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;deleteDuplicateRows() is the new function added to the script of the previous blog. Also, the menu item is extended to add the function.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Similar to the previous blog, you can now just:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Save the code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reload the spreadsheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And execute the function.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You’ll able to see the menu with the title “&lt;strong&gt;Highlight Duplicate Rows&lt;/strong&gt;“.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw97becxvvqd68706m4ri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw97becxvvqd68706m4ri.png" alt="Menu" width="691" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you can check duplicate rows  in your spreadsheet and delete them if you want with ease.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;I make Google Add-Ons and can also write Google Apps Scripts for you. If you need my services let me &lt;a href="https://nibeshkhadka.com/contact"&gt;know&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Don’t forget to like and share this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsql97aq2nkyprcyqtaay.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsql97aq2nkyprcyqtaay.png" alt="Like, Share and Follow" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googlesheets</category>
      <category>deleteduplicaterows</category>
      <category>googleappsscript</category>
      <category>googlesheetsautomation</category>
    </item>
    <item>
      <title>Using Apps Script to Count Checkboxes in Google Sheets</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Thu, 09 Mar 2023 14:52:32 +0000</pubDate>
      <link>https://dev.to/kcl/using-apps-script-to-count-checkboxes-in-google-sheets-217g</link>
      <guid>https://dev.to/kcl/using-apps-script-to-count-checkboxes-in-google-sheets-217g</guid>
      <description>&lt;p&gt;You have checkboxes in your spreadsheet, you’ll like to count them easily. Well, this script I’ll provide will help you with exactly that. Non-coders can easily follow instructions and add this script to their projects.&lt;/p&gt;

&lt;p&gt;Namaste! This is Nibesh Khadka. I am a freelancer that develops scripts to automate Google Workspace Apps like Gmail, Google Sheets, Google Docs, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  For Non-Coders
&lt;/h2&gt;

&lt;p&gt;If you’re not a coder and don’t wanna be bothered with a tedious explanation then you can just follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Script editor. On your spreadsheet click the extensions tab and open the apps script as shown in the image above.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove all the code in code.gs. Then, copy and paste the code from the Full Code section in this blog.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save and then reload the spreadsheet. Now, reopen the Apps script as instructed in step 1 (&lt;em&gt;Sometimes the script doesn't work without saving and reloading&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After this, you just have to make a minor edit as instructed below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full Code
&lt;/h2&gt;

&lt;p&gt;Here’s the full script for this blog:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// make minor change here.
// insert the number equivalent of your column with checkboxes here inside square boxes, like [1,2]
// for instance 1 for A, 5 for E, and so on.
const checkBoxColNumber = [5, 8];

/**
 * The function creates a custom menu in spreadsheet
 */
function menu() {

  SpreadsheetApp.getUi()
    .createMenu("Count Checkboxes")
    .addItem("Count Checkboxes", "countCheckbox")
    .addToUi();

}

/**
 * OnOpen is resposbile to insert menu to spreadsheet.
 */
function onOpen(e) {
  menu();
}



/**
 * CountCheckbox goes through the active sheet and counts the number of checked and unchecked box among non-empty rows
 */
function countCheckbox() {

  // get sheet and data
  let sheet = SpreadsheetApp.getActiveSheet();
  let data = sheet.getDataRange().getValues();
  // remove first header column
  data.shift();

  // initate counts as zero
  let trueCount = 0;
  let falseCount = 0;

  // value count will be a nested list but as same length as Counting Checkboxes
  let checkBoxColValueCounts = [...checkBoxColNumber];

  // loop through checkBoxColNumber list and data list 
  for (let j = 0; j &amp;lt; checkBoxColNumber.length; j++) {
    for (let i = 0; i &amp;lt; data.length; i++) {
      // [...new Set(data[i])].filter(String) check to get unique value if its either just true or false
      if ([...new Set(data[i])].filter(String)[0] === true || [...new Set(data[i])].filter(String)[0] === false || data[i].join("") === "") { continue; }
      // if values is true push increase true count else false count
      if (data[i][checkBoxColNumber[j] - 1] === true) {
        trueCount += 1;

      } else {
        falseCount += 1;

      }
    }

    // add true and false count as nested list in respective place
    checkBoxColValueCounts[j] = [trueCount, falseCount];
    // reset 
    //console.log(checkBoxColValueCounts)
    trueCount = 0;
    falseCount = 0;
  }

  // create alert string with all info embeded
  let countStatsString = "";
  for (let j = 0; j &amp;lt; checkBoxColValueCounts.length; j++) {
    countStatsString += `\n In the ${checkBoxColNumber[j]} column, There are ${checkBoxColValueCounts[j][0]} boxes checkd and ${checkBoxColValueCounts[j][1]} unchecked boxes among non-empty rows.`
  }
  // alert the result
  SpreadsheetApp.getUi().alert(countStatsString);
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Script in Your Spread Sheet
&lt;/h2&gt;

&lt;p&gt;For this script to work in your spreadsheet you’re gonna have to make a tiny change in code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// make minor change here.
// insert the number equivalent of your column with checkboxes here inside square boxes, like [1,2]
// for instance 1 for A, 5 for E, and so on.
const checkBoxColNumber = [5, 8];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See this code in the beginning, you’ll have to  replace [5, 8] these values with the number equivalent of the letters representing the columns with the checkbox  values in your spreadsheet. For instance, 5 for E and 8 for H. If it’s just one column then just insert one value inside the square box without the comma like [5].&lt;/p&gt;

&lt;h2&gt;
  
  
  Navigating the Menu
&lt;/h2&gt;

&lt;p&gt;After this, you should save the script and reload your spreadsheet you should be able to see the menu in your spreadsheet, with the title “Count Checkboxes“ similar to the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxshmyij16zjconq41px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxshmyij16zjconq41px.png" alt="Navigating Menu" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you run this function you’ll see an alert box with the sum of all checked and unchecked boxes for non-empty rows in your spreadsheet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3k3yq843662s51y0mpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3k3yq843662s51y0mpq.png" alt="Count Checkbox Result" width="800" height="290"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;p&gt;If you would like me to write short and quick blogs like these then leave requests in the comments.&lt;/p&gt;

&lt;p&gt;I make Add-Ons for Google and can also write Google Apps Scripts for you. If you need my services let me &lt;a href="https://linkedin.com/in/nibesh-khadka"&gt;know&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq44jwfq6yjue6ogwcmkb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq44jwfq6yjue6ogwcmkb.png" alt="Like, Share and Follow" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>javascript</category>
      <category>spreadsheet</category>
      <category>googlesheets</category>
    </item>
    <item>
      <title>How to Highlight Duplicate Rows in Google Sheets?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Wed, 01 Mar 2023 07:13:57 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-highlight-duplicate-rows-in-google-sheets-19mo</link>
      <guid>https://dev.to/kcl/how-to-highlight-duplicate-rows-in-google-sheets-19mo</guid>
      <description>&lt;p&gt;You use sheets a lot and sometimes have difficulty identifying duplicate rows. Then after this blog, you’ll be equipped with a script that’ll highlight duplicate rows in your sheet.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Namaste! This is Nibesh Khadka. I am a freelancer that develops scripts to automate Google Workspace Apps like Gmail, Google Sheets, Google Docs, etc.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/FXo3Snwpf84"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  For Non-Coders
&lt;/h2&gt;

&lt;p&gt;If you’re not a coder and don’t wanna be bothered with an explanation then follow this step:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9rmskydeg7kzbiv27uoa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9rmskydeg7kzbiv27uoa.png" alt="Open Apps Script" width="668" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Script editor. On your spreadsheet click the extensions tab and open the apps script as shown in the image above.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove all the codes in Code.gs. Then copy and paste the code from the Full Code section in this blog.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save and then reload the spreadsheet.Now, reopen the Apps script as instructed in step 1 (Sometimes the script doesn't work without saving and reloading).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Full Code
&lt;/h2&gt;

&lt;p&gt;Here’s the full script for this blog.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Function finds and highlights duplicate rows with unique colors
 */
function colorDuplicateRows() {
  // get sheets and data
  const ss = SpreadsheetApp.getActiveSheet();
  let data = ss.getDataRange().getValues();

  // get last col
  const lastCol = data[0].length;

  // convert rows in data to strings for easy comparision
  data = data.map(row =&amp;gt; row.join(""));

  // extract unique rows
  const uniqueRows = [... new Set(data)].filter(String);// also remove empty string if there were empty rows

  // unique color object to hold color for each unique row
  const uniqueColor = {};
  // fill the values;
  uniqueRows.forEach(row =&amp;gt; uniqueColor[row] = getRandomUniqueColor());

  // find duplicate rows indexes in the data
  const duplicateRowsIndexes = data.map((row, ind) =&amp;gt; isDuplicateRow(row, data) ? ind + 1 : "").filter(String);

  // reset color to default before applying new colors
  colorReset();

  // highlight duplicate rows
  duplicateRowsIndexes.forEach(rowInd =&amp;gt; {
    const range = ss.getRange(rowInd, 1, 1, lastCol) // get range
    // highlight
    range.setBackground(uniqueColor[range.getValues().flat().join("")])
  })

}

/**
 * Function takes two items: row and arr.
 * The parameter "row" is a string to be compared to items in array "arr".
 * Inspired from https://stackoverflow.com/a/68424642/6163929
 * @param {String} row
 * @param {Array&amp;lt;String&amp;gt;} arr
 * @returns {Boolean}
 */
function isDuplicateRow(row, arr) {
  return row === "" ? false : arr.indexOf(row) != arr.lastIndexOf(row);
}

/**
 * Menu creates menu UI in spreadsheet.
 */
function createCustomMenu() {
  let menu = SpreadsheetApp.getUi().createMenu("Highlight Duplicate Rows"); 

  menu.addItem("Highlight Duplicate Row", "colorDuplicateRows");
  menu.addItem("Reset Colors", "colorReset");
  menu.addToUi();
}

/**
 * OnOpen trigger that creates menu
 * @param {Dictionary} e
 */
function onOpen(e) {
  createCustomMenu();
}

/**
 * ColorReset is used to reset bg color of spreadsheet to its original color.
 */
function colorReset() {
  let sheet = SpreadsheetApp.getActiveSheet();
  sheet.getDataRange().setBackground("");
}

/**
 * Function creates a unique random color as hashcode.
 * @returns {String}
 */
function getRandomUniqueColor() {
  // thanks to function https://dev.to/rajnishkatharotiya/generate-unique-color-code-in-javascript-3h06
  let n = (Math.random() * 0xfffff * 1000000).toString(16);
  return "#" + n.slice(0, 6);
}

/**
 * Code By Nibesh Khadka.
 * I am freelance and Google Workspace Automation Expert.
 * You can find me in:
 * https://linkedin.com/in/nibesh-khadka
 * https://nibeshkhadka.com
 * me@nibeshkhadka.com
 */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Is The Row Duplicate?
&lt;/h3&gt;

&lt;p&gt;To find if a row is duplicate or not we’re using &lt;strong&gt;isDuplicateRow()&lt;/strong&gt; function in our script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isDuplicateRow(x, arr) {
  return x === "" ? false : arr.indexOf(x) != arr.lastIndexOf(x);
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function takes two parameters: a string and an array. The string is a row converted to a string and an array is a list of rows each converted to a string.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reset Color and Random Unique Color
&lt;/h3&gt;

&lt;p&gt;To highlight duplicate rows we’ll have to do two things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The first is to reset previous highlights(if they exist) with the &lt;strong&gt;colorReset()&lt;/strong&gt; function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then color them with colors that are unique to each set of duplicate rows, with the &lt;strong&gt;getRandomUniqueColor()&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function colorReset() {
  let sheet = SpreadsheetApp.getActiveSheet();
  sheet.getDataRange().setBackground("");
}


function getRandomUniqueColor() {
  // thanks to function https://dev.to/rajnishkatharotiya/generate-unique-color-code-in-javascript-3h06
  let n = (Math.random() * 0xfffff * 1000000).toString(16);
  return "#" + n.slice(0, 6);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You should know that the colors will be different each time you run the function since they are random. In real-world use cases, it is difficult to hardcode colors because the number of sets of duplicate rows can vary.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Lets Color Duplicate Rows
&lt;/h3&gt;

&lt;p&gt;Now that all the helper functions are ready let’s put them all in a proper order to color the duplicate rows in our sheet with our &lt;strong&gt;colorDuplicateRows()&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function colorDuplicateRows() {
  // get sheets and data
  const ss = SpreadsheetApp.getActiveSheet();
  let data = ss.getDataRange().getValues();

  // get last col
  const lastCol = data[0].length;

  // convert rows in data to strings for easy comparision
  data = data.map(row =&amp;gt; row.join(""));

  // extract unique rows
  const uniqueRows = [... new Set(data)].filter(String);// also remove empty string if there were empty rows

  // unique color object to hold color for each unique row
  const uniqueColor = {};
  // fill the values;
  uniqueRows.forEach(row =&amp;gt; uniqueColor[row] = getRandomUniqueColor());

  // find duplicate rows indexes in the data
  const duplicateRowsIndexes = data.map((row, ind) =&amp;gt; isDuplicateRow(row, data) ? ind + 1 : "").filter(String);

  // reset color to default before applying new colors
  colorReset();

  // highlight duplicate rows
  duplicateRowsIndexes.forEach(rowInd =&amp;gt; {
    const range = ss.getRange(rowInd, 1, 1, lastCol) // get range
    // highlight
    range.setBackground(uniqueColor[range.getValues().flat().join("")])
  })

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Ya.. Ok, But where’s the menu?
&lt;/h3&gt;

&lt;p&gt;Our function is ready it will work every time you run the function from the script(if not follow step 3 from the non-coders section) but we want to run this function from our sheet.&lt;/p&gt;

&lt;p&gt;So, let’s create our custom menu with the &lt;strong&gt;createCustomMenu()&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createCustomMenu() {
  let menu = SpreadsheetApp.getUi().createMenu("Highlight Duplicate Rows");

  menu.addItem("Highlight Duplicate Row", "colorDuplicateRows");
  menu.addItem("Reset Colors", "colorReset");
  menu.addToUi();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, render the custom menu to the spreadsheet with &lt;a href="https://developers.google.com/apps-script/guides/triggers#onopene" rel="noopener noreferrer"&gt;OnOpen()&lt;/a&gt; trigger.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function onOpen(e) {
  createCustomMenu();
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the code and reload the spreadsheet then you’ll able to see the menu with the title “&lt;strong&gt;Highlight Duplicate Rows&lt;/strong&gt;“.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyru29f29s93w1s6bwxy2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyru29f29s93w1s6bwxy2.png" alt="Custom Menu" width="661" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You for Your Time
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;I make Google Add-Ons and can also write Google Apps Scripts for you. If you need my services let me &lt;a href="https://nibeshkhadka.com/contact/?ref=hackernoon.com" rel="noopener noreferrer"&gt;know&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2wujqjamcgzsaoshr2u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs2wujqjamcgzsaoshr2u.png" alt="Follow Me" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>saas</category>
      <category>automation</category>
      <category>productivity</category>
      <category>workflow</category>
    </item>
    <item>
      <title>Find and Delete Duplicate Files With In Google Drive With Google Apps Script</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Wed, 22 Feb 2023 09:33:25 +0000</pubDate>
      <link>https://dev.to/kcl/find-and-delete-duplicate-files-with-in-google-drive-with-google-apps-script-2pj1</link>
      <guid>https://dev.to/kcl/find-and-delete-duplicate-files-with-in-google-drive-with-google-apps-script-2pj1</guid>
      <description>&lt;p&gt;Liquid syntax error: Unknown tag 'endraw'&lt;/p&gt;
</description>
      <category>googleappsscript</category>
      <category>javascript</category>
      <category>googledrive</category>
      <category>automation</category>
    </item>
    <item>
      <title>How to Find the Last Non-Empty Row in A Column With Google Apps Script?</title>
      <dc:creator>Nibesh Khadka</dc:creator>
      <pubDate>Thu, 26 Jan 2023 13:29:22 +0000</pubDate>
      <link>https://dev.to/kcl/how-to-find-the-last-row-in-a-column-with-google-apps-script-3npa</link>
      <guid>https://dev.to/kcl/how-to-find-the-last-row-in-a-column-with-google-apps-script-3npa</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;I am writing this short blog to share a solution to a problem that has been bugging me for a while, which is to find the last row in a column accurately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Usually, when you use google apps script and want to find the last non-empty row we use something similar to the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//...... 
// after certain codes
//last row
let lastRow = sheet
      .getRange(1, 1)
      .getNextDataCell(SpreadsheetApp.Direction.DOWN)
      .getRow();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you've used this code then you know that this doesn't always work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helper Function
&lt;/h2&gt;

&lt;p&gt;But first, a function to get all columns in a spreadsheet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getColumnNames() {
  let spreadsheet = SpreadsheetApp.openById(SPRD_ID);
  let activeSheet = spreadsheet.getSheetByName(SHEET_NAME);
  let lastCol = sheet
    .getRange(1, 1)
    .getNextDataCell(SpreadsheetApp.Direction.NEXT)
    .getColumn();

 // find the corrent index of url column
  let columns = activeSheet.getRange(1, 1, 1, lastCol).getValues().flat();
  console.log(columns)
  return columns;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;So, this solution in stack overflow suggests using the logic of finding the last non-empty row starting from the bottom. I have modified this code to suit my needs.&lt;/p&gt;

&lt;p&gt;Then the following code can calculate the last row of a column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getUrlColumnNRowNumber(colName = "Email") {

  try {
    let spreadsheet = SpreadsheetApp.openById(SPRD_ID);
    let activeSheet = spreadsheet.getSheetByName(SHEET_NAME);

    // find the corrent index of url column
    let columns = getColumnNames();
    let ind = columns.findIndex((val) =&amp;gt; val.toLowerCase().trim() === colName.toLowerCase().trim());

    // check if -1 is returned else increase index by 1 to match with index system of spreadsheet
    let colIndex = ind === -1 ? null : ind + 1;
    if (colIndex === null) throw { "error": "No Column Name Found" };

    let maxRows = activeSheet.getMaxRows();
    // ger all the values with emtpy rows
    let columnRaw = activeSheet
      .getRange(2, colIndex, maxRows, 1)
      .getValues()
      .flat();

    let columnRawReverse = [...columnRaw].reverse();
    // find first non empty value  in the list 
    let firstNonEmptyCell = columnRawReverse.findIndex((el) =&amp;gt; el !== "");

    // subtract it with maxrows and add 1 becuase range started from 2.
    //  if all rows are empty then return 2 
    let lastRowInCol = firstNonEmptyCell !== -1 ? maxRows - firstNonEmptyCell + 1 : 2;
    console.log([colIndex, lastRowInCol]);
    return [colIndex, lastRowInCol];
  }
  catch (e) {
    if (e.error === "No Column Name Found") {
      console.log("No column found");
      return [null, null]
    }

  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;If you've understood the code then no need to read further.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;Let's go over some minor details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// find the corrent index of url column
    let columns = getColumnNames();
    let ind = columns.findIndex((val) =&amp;gt; val.toLowerCase().trim() === colName.toLowerCase().trim());

   // check if -1 is returned else increase index by 1 to match with index system of spreadsheet
    let colIndex = ind === -1 ? null : ind + 1;
    if (colIndex === null) throw { "error": "No Column Name Found" };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we get column names i.e, the first row from the spreadsheet. Then, on the second line, we check if the column name exists in the spreadsheet if not we are throwing an error, however, if it exists then we return the column index.&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    let maxRows = activeSheet.getMaxRows();
    // ger all the values with emtpy rows
    let columnRaw = activeSheet
      .getRange(2, colIndex, maxRows, 1)
      .getValues()
      .flat();

    let columnRawReverse = [...columnRaw].reverse();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we get the max number of rows in the current spreadsheet. Get the values in the column we're checking. The reverse is done to implement the &lt;strong&gt;findIndex()&lt;/strong&gt; method next. Remember we're fetching values from the second row so, if the column is empty we have to consider this as well.&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
  // find first non empty value  in the list 
    let firstNonEmptyCell = columnRawReverse.findIndex((el) =&amp;gt; el !== "");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we use the &lt;strong&gt;findIndex()&lt;/strong&gt; method to find the first non-empty value in the reversed list.&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // subtract it with maxrows and add 1 becuase range started from 2.
    //  if all rows are empty then return 2 
    let lastRowInCol = firstNonEmptyCell !== -1 ? maxRows - firstNonEmptyCell + 1 : 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;findIndex()&lt;/strong&gt; returns -1 if the condition is not satisfied and if so then, we'll return 2 as the last row. Else, just subtract the index returned, with max rows, and then add 1(because we fetched the value from the second row).&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2For8g8ls5dicypme6nn6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2For8g8ls5dicypme6nn6o.png" alt="Khadka's Coding Lounge" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank You
&lt;/h2&gt;

&lt;p&gt;This is Nibesh Khadka from Khadka's Coding Lounge. Find my blogs here. Please do like and share if you like my work. Also, subscribe to get notified about the next upload.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I make Google Add-Ons and can also write Google Apps Scripts for you. If you need my services let me know &lt;a href="https://nibeshkhadka.com/contact/" rel="noopener noreferrer"&gt;directly&lt;/a&gt; or from &lt;a href="https://www.fiverr.com/coder_dai93?public_mode=true" rel="noopener noreferrer"&gt;fiverr&lt;/a&gt; or &lt;a href="https://www.upwork.com/freelancers/~010aeac3f0f562ed69" rel="noopener noreferrer"&gt;upwork&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thank you for your time.&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
