To automatically create and remove borders in Excel with
conditional formatting based on the formula $B2<>"", you can
follow these steps:
Select the range of cells where you want the borders to be
applied.
Go to the "Home" tab in the Excel ribbon and click
on "Conditional Formatting".
Select "New Rule" and choose the option "Use
a formula to determine which cells to format".
In the formula bar, enter the formula
$B2<>"".
Click on the "Format" button and go to the
"Border" tab.
Choose the type of border you want to apply (e.g. thick,
dotted, etc.) and click on "OK".
Click on "OK" again to apply the rule.
This will apply borders to all the cells in the selected
range that contain any value in column B. The $ symbol before the column letter
($B2<>"") will make sure that the formula is applied to all the
rows in the selected range but only to column B.
To remove the borders when the cells in column B are empty,
you can create a second rule that uses the same formula but applies no border.
Follow steps 1-4 above, and in the formula bar, use the same formula as before
($B2<>""). Then, instead of going to the "Border"
tab, go to the "Fill" tab and choose "No Fill". Click on
"OK" to apply the rule.
Now, when a cell in column B is empty, the borders will be automatically removed.