How to Search for Word in Multiple Selection Dropdown Cell in Apps Script

Learn how to search for a specific word within a multiple selection dropdown cell using Google Apps Script, enhancing your Google Sheets functionality.

We want to search for a word in a multiple selection drop down cell. I'm going to show you how we search for words regularly and then how we can change this. So we have these sales goals, January, February, all through the month. And we have a check box and we have a dropdown that actually allows us to have multiple selections to, So ideally maybe clean this up in some way visually or just have this sort of database that says 21 is the goal for January, February, and March instead of three rows here. So however you have it, I'm going to show you a simple way to search for words in this C column. Create a function called find. This is in Apps Script . It can be found in Extensions, Apps Script here. We're going to have variable column. Find Keywords in Any Column. Create quick search dropdown to find keywords Find New Additions to a Main List in Google Sheets Deep Inside Dark Habits Google Script How to Change Dropdown Colors and Gray Out Rows in Google Sheets with Apps Script

And that variable of a column is going to be the entire column we're searching through. Spreadsheet app dot get active spreadsheet . Get sheet by name. Here, it's just sheet one. Get range . C colon C. In quotes. And get values . Now this get values is going to be an array. Let's log that to show you. what that column might look like. I'll click run, and we see here that we have each item in an array inside of the array. So we can access in Apps Script the entire column of all those values. Now to actually go through each and every one of them and find out what's in it, we're going to use a for loop. This is just for i equals 0, we'll set it up that it starts at 0, i is less than column dot length, and we're going to iterate. Tips to Navigating Thousands of Lines of Code In Apps Script Getting Started Coding in Apps Script Get Sheet ID and Tab GID Into Your Google Sheet Get Values from Sheet for Custom Function in Apps Script

I one each time. Now inside of this for loop, if column bracket I zero, the first item in that first array is equal to January, we're going to do something here. And let's just log that we found And January in row, and here we're going to do plus. I plus 1, because we're starting at 0, so the first row would be 0 plus 1 is 1. So we're going to log that if we find January. Now again, our sheet looks like this right now, but we're going to change it to have multiple selections. Let's click and run find. And we found it in row 2. Let's say we had it in multiple columns, run it again, and we found it in row 2 and row 3, so we could execute something based on that if statement. But in our multiple selection , we may have January, February, March. Spreadsheet Automation 101 Lesson 2: Bracket Notation Figure Out Frequency of Numbers Visicalc 2023 Design Walkthrough SHEETS and SHEET NEW FORMULAS in Google Sheets

We may have January, February. And now January doesn't exist alone, so if we use this, we find nothing. So we need to change this. And what we need to do is a very simple change. This , column I zero, dot includes, and in here, use January. So instead of we're looking for the E, Equaling, we're just saying, does January exist in this string ? Let's run it. And now we found in row two and three, even though it is multiple selection selected. And I think that's pretty cool because what's going on in the background is that this multiple selection is just a comma separated values set of text. Let's actually look at that. We can. Say, what is this here is column I, let's just log what that is when we What is this Ampersand Doing in Google Sheets? Highlight Duplicates of Two Columns

run it and see it is a comma separated values list of January, February, March. So we just need that includes and you're good to go for your Apps Script for your automations. Hope you enjoyed that. Hope you get awesome stuff out of your Google Sheets. And if you're not, make sure you subscribe today to better sheets here on YouTube. Get Sheets Wrapped 2024 | Your Year in Google Sheets This Week in Better Sheets - Feb 12th, 2023 Now Do It Every Damn Day - Learn to Code in Google Sheets Part 5 Create a Tab for Every Month in Google Sheets with Apps Script