macro to insert think border from Total Value Col A to Col F

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,566
Office Version
  1. 2021
Platform
  1. Windows
I have 'Total Value" in Col A 3 rows below the last value and total values in Col B:F , 3 rows after the last value


I have written code to insert a thick outside border from Total value and 5 columns to the right -see sample data below

However when running my macro nothing happens

It would be appreciated if someone cold assist me

Thick Outside Border.xlsx
ABCDEF
12Total Value330847181011100557913560644
Sheet1





Code:
 Sub Totals()
Dim c As Range
With Sheet1
Set c = .Columns(1).Find("Total Value", , , 1)
If Not c Is Nothing Then
c.Offset(, 1).Resize(, 5).Value = "=sum(b1:b" & c.Row - 1 & ")"
Else

lr = .Cells(.Rows.Count, 1).End(xlUp).Row
.Cells(lr + 3, 1).Value = "Total Value"
.Cells(lr + 3, 2).Resize(, 5).Value = "=sum(b4:b" & lr & ")"
.Cells(lr + 3, 2).Resize(, 5).NumberFormat = "#,##0.00"
.Cells(lr + 3, 2).Resize(, 5).Font.Bold = True
.Cells(lr + 3, 1).Resize(, 5).Borders(xlEdgeLeft).LineStyle = xlContinuous
.Cells(lr + 3, 1).Resize(, 5).Borders(xlEdgeTop).LineStyle = xlContinuous
.Cells(lr + 3, 1).Resize(, 5).Borders(xlEdgeBottom).LineStyle = xlContinuous
.Cells(lr + 3, 1).Resize(, 5).Borders(xlEdgeRight).LineStyle = xlContinuous
.Cells(lr + 3, 1).Resize(, 5).Borders(xlInsideVertical).LineStyle = xlContinuous
.Cells(lr + 3, 1).Resize(, 5).Borders(xlInsideHorizontal).LineStyle = xlContinuous

          
End If
End With
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Maybe this
VBA Code:
Sub Totals()
Dim c As Range
With Sheet1
Set c = .Columns(1).Find("Total Value", , , 1)
If Not c Is Nothing Then
c.Offset(, 1).Resize(, 5).Value = "=sum(b1:b" & c.Row - 1 & ")"
Else

lr = .Cells(.Rows.Count, 1).End(xlUp).Row
.Cells(lr + 3, 1).Value = "Total Value"
.Cells(lr + 3, 2).Resize(, 5).Value = "=sum(b4:b" & lr & ")"
.Cells(lr + 3, 2).Resize(, 5).NumberFormat = "#,##0.00"
.Cells(lr + 3, 2).Resize(, 5).Font.Bold = True
.Cells(lr + 3, 1).Resize(, 5).Borders.LineStyle = xlContinuous
End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,443
Messages
6,124,890
Members
449,194
Latest member
JayEggleton

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