Add a Button To Automate Add a Row with Category

Learn how to automate adding a new row with a category selection in Google Sheets using a custom button and Google Apps Script. This tutorial simplifies the process, allowing you to add rows with just one click.

We wanna add a button to automate adding a new row, but when we add that new row, we wanna pick the category before we do it. Of course, we could go to this second row, insert row above, select the category, but that's a lot of buttons to click. Let's do it in one click. We're going to need an app script . Go to extensions app script . We will call this add fruit because we're gonna have multiple categories. We have fruit, meat, vegetable. Let's do a couple. Let's do at least fruit. We're going to first. Go spreadsheet app. Do get active sheet . Do insert row before you might think we're gonna insert a row after one, but actually wanna do insert row before two because if we do insert row after one, we'll inherit all of the design and format of the header row. How to Insert Multiple Rows in Google Sheets (Easy to Hard) Automate Row Deletion in Google Sheets with Apps Script Basic CRM - Add a Powerful Script To Move Row Based on Status How To Insert Row Under Header Automatically

But if we do insert row before two, we will get all of the formatting of the second row in our new row. And the next thing we need to do is spreadsheet . Do get active sheet dot get range , and in which column? Column D. So that's gonna be row two, column four, and only one cell. We're gonna set value and that's going to be fruit. Just in text. What's gonna happen is when we insert a row above, that dropdown menu will be inherited. So we just need to set the value to the dropdown value we want, which is just text. So we can test this out. We can say, add fruit, click run, see if there's any errors here, and we don't have any errors and we have a new row with fruit on it, How to Insert Multiple Rows in Google Sheets (Easy to Hard) Writer Better Prompts How To Insert Row Under Header Automatically

but let's create that button here. With insert drawing , and we're going to choose a nice shape, like a beveled shape here, and we're gonna say add, actually, we're gonna say fruit. That's all we want to say. Fruit. Maybe we change this to green. To better match the green of fruit. Click and drag it over here. And now we need to make sure this function add fruit is assigned to this button. So in the top right corner, there's three buttons. We're gonna click that assign script and paste just the name of the script here, click okay. We can do this again. We can insert drawing again. Go and create a new beveled one and call it vegetable. Create Navigation Buttons in Sheets to Other Sheets Click, New Sheet

Make it a little bit smaller just to fit that vegetable. Do it dark green, maybe with white text here. Safe and close, and we're gonna need to create a new function . Add vegetable. Add vegetable, and instead of set value fruit vegetable. Copy this function . Save this. Make sure you save it. Go back to our sheet. Click on our three dots in the upper right corner. Assign script, add vegetable, click okay, and now we have a fruit and a vegetable next to each other there. Click vegetable and we have a new vegetable row. We can do that with meat and dairy as well and create multiple buttons here. Very cool. I hope you enjoyed that. If you're looking to get more out of your Google sheets, do How to Merge Cells in Google Sheets Make It Easier For Others To Use Your Google Sheets Advanced Coding in Google Sheets for Programmers Button Styles

more in your Google sheets. Get more animations in your Google sheets. Subscribe today to better sheets on YouTube right here. Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets. 80 Years In 1 Spreadsheet Better Sheets Videos Checklist Spintax Content Spinner for Google Sheets