add borders to range of cells that changes each day

excel01noob

Board Regular
Joined
Aug 5, 2019
Messages
93
Office Version
  1. 365
  2. 2016
Hi

In my team we have a daily set of data which we need to analyse and send to the teams members.
As the summary of analysed data is sent by email I want to send it in a way that the data has borders on it.


In terms of columns, it goes from column A to L.
In terms of rows, data will vary from day to day.

How can I insert a code that would do the borders for this data that changes each day ?

Thank you in advance
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I'm using this code but the borders are being put to all cells between A to L
Code:
Sub borders()

Dim cell As Range

For Each cell In ActiveSheet.Range("A:L")

    With cell.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThin
    End With
    With cell.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With cell.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With cell.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With

    Next cell

End Sub
 
Last edited by a moderator:
Upvote 0
Assuming that column A can be used to determine where the data ends, does this do what you want?
Code:
Sub Data_Borders()
  Columns("A:L").borders.LineStyle = xlNone
  With Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 12)
    .BorderAround xlContinuous, xlThin
    With .borders(xlInsideHorizontal)
      .LineStyle = xlContinuous
      .Weight = xlThin
    End With
    With .borders(xlInsideVertical)
      .LineStyle = xlContinuous
      .Weight = xlThin
    End With
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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