How do I automatically create border if the cell has content in Excel? – Excel Tips and Tricks #tips

How do I automatically create border if the cell has content in Excel? – Excel Tips and Tricks #tips

HomeOther ContentHow do I automatically create border if the cell has content in Excel? – Excel Tips and Tricks #tips
ChannelPublish DateThumbnail & View CountActions
Channel Avatar Rabi Gurung2023-07-01 13:00:40 Thumbnail
13,071 Views
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

#tip #excel #microsoft #shorts #short #shortvideo #shortsvideo #howto #how #google

Please take the opportunity to connect and share this video with your friends and family if you find it useful.