Forum

Trying to write a m...
 
Notifications
Clear all

Trying to write a macro

4 Posts
2 Users
0 Reactions
95 Views
(@dreamingbig2att-net)
Posts: 15
Eminent Member
Topic starter
 

I'm trying to write a macro.  Where Columns D:F have an auto sum form the row that has "totals" in column A. The number of rows varies each time. But the sum need to go into the highlighted rows.  I manually enter numbers for jeff and ivan so the sum needs to be able to include those cells.

I also want it to double underline the sum and single underline the row above.

Capture3.PNG

 
Posted : 12/02/2019 1:09 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Julie

Give this a try.

Sub AddSum()

Dim rw As Long
'Find the row with the word Totals in column A
rw = Application.Match("Totals", Range("A:A"))

With Range("D" & rw & ":F" & rw)
.Formula = "=SUM(D2:D" & rw - 1 & ")"
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlDouble
.Borders(xlEdgeBottom).Weight = xlThick
End With
End Sub

 

Sunny

 
Posted : 12/02/2019 8:46 pm
(@dreamingbig2att-net)
Posts: 15
Eminent Member
Topic starter
 

That worked except it puts the formula in the row titled Equipment and not the Totals row.  Sometimes it puts it in the Totals row but usually int the Equipment row.

 
Posted : 12/02/2019 11:08 pm
(@sunnykow)
Posts: 1417
Noble Member
 

My mistake Embarassed.

I left out one argument in the MATCH. I tested it without your rows 12 and 13.

Sub AddSum()

Dim rw As Long
'Find the row with the word Totals in column A
rw = Application.Match("Totals", Range("A:A"),0)

With Range("D" & rw & ":F" & rw)
.Formula = "=SUM(D2:D" & rw - 1 & ")"
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlDouble
.Borders(xlEdgeBottom).Weight = xlThick
End With
End Sub

 
Posted : 13/02/2019 12:08 am
Share: