Automatically Add ALL Borders to Cells with values only

jluangrath88

New Member
Joined
Apr 22, 2018
Messages
23
Hi All,

I currently have a worksheet called “Summary.” It has values in columns A to J. I want to add borders to every single cell that has data in it (in that worksheet only). No data, no border. Etc.

I’m already running several macros in the entire workbook so conditional formatting will not work for me. Can somebody help me or provide me with the proper VBA code?

please help
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
just loop through every cell and test if it is blank - if it is continue looping if not apply the borders

why would conditional forma
tting not work ?
 
Upvote 0
I have two specific macros running in the workbook that will clear all data from this worksheet amongst others. It’s done daily. So when that macro runs, it clears out the conditional formatting as well.
 
Upvote 0
Hi & welcome to the board
If your cells contain values rather than formulae, try
Code:
Sub AddBorders()
   With Range("A:J").SpecialCells(xlConstants)
      .Borders.Weight = xlThin
   End With
End Sub
 
Upvote 0
Partly out of habit, normally when using Specialcells I'm doing a number of things to the cells.
Also if the OP wants to change the colour, linestyle etc, I can simply add an extra line of code or 2.
 
Upvote 0
Fair enough, personally I prefer to apply it directly to the range but the minute milliseconds difference is inconsequencial :)
 
Upvote 0
""clear all data from this worksheet amongst others. It’s done daily. So when that macro runs, it clears out the conditional formatting as well.""

if you delete only the cell contents, formula or value, the borders will remain

if the borders are there via conditional formatting, they WILL disappear, but reappear when the cell is repopulated...
 
Upvote 0
""clear all data from this worksheet amongst others. It’s done daily. So when that macro runs, it clears out the conditional formatting as well.""

if you delete only the cell contents, formula or value, the borders will remain

if the borders are there via conditional formatting, they WILL disappear, but reappear when the cell is repopulated...

I’m aware of that. However, the company I work for is using this sheet to run specific codes and needs the sheet to clear out each time. Plus, the amount of rows and columns are changing constantly, so I just needed a VBA code to get started and tweak to what I need.

But thank you for your input :)
 
Upvote 0
Hi & welcome to the board
If your cells contain values rather than formulae, try
Code:
Sub AddBorders()
   With Range("A:J").SpecialCells(xlConstants)
      .Borders.Weight = xlThin
   End With
End Sub

thank you. Exactly what I needed. Just tweaked and added a bit for border style, color, etc.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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