change font to bold in macro

andre232

New Member
Joined
Sep 19, 2017
Messages
15
Hello,

I have a macro to find a range of cells and place a total below the last cell with data. I'd like it to put the sum in bold but I've only managed to get it to make the first cell with data bold. I also would like to add in some code to find the last cell with data in the A column and write "Totals:" in bold below it if you are up to it. I'm sure it is simple but I appreciate any help.

Sub Totals()

Range("C15", Range("C15").End(xlDown)).Select
Dim rng As Range
With Selection.Areas
With .Item(.Count)
.Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & Selection.Address & ")"
ActiveCell.Font.Bold
End With
End With


Range("D15", Range("D15").End(xlDown)).Select
Dim rng2 As Range
With Selection.Areas
With .Item(.Count)
.Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & Selection.Address & ")"
End With
End With

Range("E15", Range("E15").End(xlDown)).Select
Dim rng3 As Range
With Selection.Areas
With .Item(.Count)
.Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & Selection.Address & ")"
End With
End With

Range("F15", Range("F15").End(xlDown)).Select
Dim rng4 As Range
With Selection.Areas
With .Item(.Count)
.Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & Selection.Address & ")"
End With
End With
End Sub
 

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.
Try:
Code:
Sub Totals()

    Dim x   As Long
    Dim LR  As Long
    
    Application.ScreenUpdating = True

    For x = 3 To 6
        LR = Cells(Rows.count, x).End(xlUp).row
        Cells(15, x).Resize(LR - 14).Font.Bold = False
        With Cells(LR, x).Offset(1)
            .Formula = "=SUM(" & Cells(15, x).Resize(LR - 14).Address & ")"
            .Font.Bold = True
        End With
    Next x
    
    Cells(LR + 1, 1).Value = "Totals:"
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
This sums from C15 to the last row in col C, places the sum one cell below the last row in col C and makes the cell bold. Also finds last row in col A and places "Totals" in bold one cell below it.
Code:
Sub Totals()
Dim lRc As Long, lRa As Long
lRc = Range("C" & Rows.Count).End(xlUp).Row
With Range("C" & lRc + 1)
    .Formula = "=SUM(" & Range("C15", "C" & lRc).Address(0, 0) & ")"
    .Font.Bold = True
End With
lRa = Range("A" & Rows.Count).End(xlUp).Row
With Range("A" & lRa + 1)
    .Value = "Totals"
    .Font.Bold = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,262
Messages
6,123,950
Members
449,134
Latest member
NickWBA

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