VBA code for formatting certain cells to include a border

lgrande

Board Regular
Joined
Nov 2, 2012
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon,

Looking for help. I am looking for a code that will apply borders to the cells that have data in them in column Column A13 (down till the last populated cell in A13) over to column E13 (to the same last populated cell found in A13. The amt of lines will vary each time. I appreciate any help you can give me.

Thank you,

Linda G
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:
VBA Code:
Sub AddBorders()
    Range("A13", Range("E" & Rows.Count).End(xlUp)).Borders.LineStyle = xlContinuous
End Sub
 
Upvote 0
Solution
Why not just use Conditional Formatting (no VBA necessary)?

Simply select the cells starting from A13 over to column E down as far as you might ever need to go.
Then go to Conditional Formatting, select the "Use a formula to determine which cells to format" option, and enter in this formula:
Excel Formula:
=A13<>""
and choose square Border formatting option.
 
Upvote 0
Why not just use Conditional Formatting (no VBA necessary)?

Simply select the cells starting from A13 over to column E down as far as you might ever need to go.
Then go to Conditional Formatting, select the "Use a formula to determine which cells to format" option, and enter in this formula:
Excel Formula:
=A13<>""
and choose square Border formatting option.
Thank you. I will try that
 
Upvote 0
Note that when you mark a post as the solution, please mark the original post containing the solution, and not your own post acknowledging that some other post is the solution.
I have updated this thread for you.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top