Ask Your Question
3

How can I use VBA to create a border around cells that have text or a value in them?

asked 2023-03-15 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-08-09 02:00:00 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-15 11:00:00 +0000

Seen: 12 times

Last updated: Aug 09 '21