Ask Your Question

Revision history [back]

Here is a VBA code that will create a border around cells that have text or a value in them:

Sub AddBorders()

Dim cell As Range

For Each cell In ActiveSheet.UsedRange
    If cell.Value <> "" Then 'if the cell has text or a value
        cell.BorderAround xlContinuous 'add a border around the cell
    End If
Next cell

End Sub

To use this code, open the Visual Basic Editor (VBE) by pressing Alt + F11 in Excel. Then, insert a new module and copy and paste the code into the module. Press F5 to run the code and it will add borders around cells that have text or a value in them.