Hosted by Dailymotion. For legal issues report at the Copyright Center, report us on DMC, or use the Instant Removal tool.
How do I automatically create border if the cell has content in Excel? - Excel Tips and Tricks
7 Views • Aug 14, 2025
Description
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?,
More from User
Custom Sort Rows in Excel - Excel Tips and Tricks
ExcelTips247
How to Make Excel Formulas Calculate Automatically - Excel Tips and Tricks
ExcelTips247
Highlight duplicate cell in another sheet in Excel - Excel Tips and Tricks
ExcelTips247
How do you align charts to cells in Excel? - Excel Tips and Tricks
ExcelTips247
Hide cell values in Excel - Excel Tips and Tricks
ExcelTips247
How do I add a Choosecols function in Excel? - Excel Tips and Tricks
ExcelTips247
Related Videos
How to Make Borders Automatically Appear as Data is Added - Excel Tips and Tricks
ExcelTips247
How to Make Excel Formulas Calculate Automatically - Excel Tips and Tricks
ExcelTips247
Excel Automatically Sort When Data Changes or Added - Excel Tips and Tricks
ExcelTips247
How do you create dynamic cell borders in Excel? - Excel Tips and Tricks
ExcelTips247
Insert picture in Excel cell automatically - Excel Image Assistant
Thanh Crook
How to Automatically Insert Date in Excel | Easy Tips & Tricks for Fast Auto-Fill
Mr. EXCEL HACKS