Skip to playerSkip to main contentSkip to footer
  • 6 weeks ago
Learn how do I automatically create border if the cell has content in Excel or in other words, how do you conditional format borders in Google sheet? Another way to ask the question is how to automatically add borders around non empty cells. Or simply to put it how do I add an automatic border, or how to create dynamic cell borders in Google sheet?

Here are the steps outline on the video.

Dynamically Add borders in a cell
1) Extensions
2) Apps Script
3) Type the script below.
4) Save
5) Go to Google Sheet
6) Refresh the webpage (F5)


Here's how it works:
1) The program defines a function named onEdit that takes a single parameter e. This function will be triggered whenever a user makes an edit in the spreadsheet.
2) Inside the onEdit function, the program retrieves the edited range using e.range. This range represents the cell or cells that were edited.
3) The program then gets the value of the edited range using range.getValue(). This retrieves the content of the edited cell.
4) Next, the program checks if the value of the edited cell is an empty string ("") by comparing value === "". If the value is empty, it means the user has cleared the cell.
5) If the value is empty, the program uses the setBorder method of the range object to remove all borders from the edited range. It accomplishes this by passing false as arguments for all border sides: top, right, bottom, left, vertical, and horizontal.
6) If the value is not empty (i.e., the user has entered or modified a value in the cell), the program uses the setBorder method again, but this time passes true as arguments for all border sides. This applies a solid border to the edited range.
7) The program finishes executing, and the border formatting is applied to the edited cell(s) based on the value.
Overall, the program automatically applies or removes borders to the edited cell(s) depending on whether they are empty or have a value. This can be useful for visually distinguishing between cells that are filled and those that are empty in a Google Sheets spreadsheet.

Note that, when you click on run, you might get an error that says "TypeError: Cannot read properties of undefined (reading 'range')". Note that the onEdit function is an event handler that automatically runs when a user edits a cell in the spreadsheet. To fix the error, you need to trigger the function by actually making an edit in the Google Sheets UI, rather than running it manually from the script editor.


🔗🔗 LINKS TO SIMILIAR VIDEOS 🔗🔗
How do you create dynamic cell borders in Excel? - Excel Tips and Tricks
https://youtube.com/shorts/vGegExuZ-LA?feature=share


How do I conditionally Format borders in Google Sheets?,Automatically add borders around nonempty cells,How do I add an automatic border?,How do you automatically create borders if a cell has contents in Excel?,
Transcript
00:00This is how you can dynamically add borders in Google Sheet. Yes, that's right. In my previous
00:04video, I did say you cannot do it in Google Sheet, but somehow did prove me wrong. I gotta love my
00:09community of viewers. Anyway, without further ado, this is how I do it. First, you're gonna go to
00:14Extension, and then go to App Script. Once the App Script launches, paste this script in your
00:21App Script project here. I'll leave the script in the description. If you need this script right
00:26away, do let me know in the comment section, and I'll send you on your comment, and then
00:30click on Save here. Once that's saved, you're gonna go to go back to your Google Sheet here
00:35and press F5. And now, if you add any row like this, you can see that the borders are drawn
00:45dynamically on the cell.
Be the first to comment
Add your comment

Recommended