Macro - Format Totals?

Glenn

Active Member
Joined
Sep 20, 2003
Messages
325
Hi,

I'm using this macro to get the totals of some columns:
Code:
Sub xxx()
Dim x As Range
Set x = Range("B65536").End(xlUp)
x.Offset(1, 6).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
x.Offset(1, 7).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
x.Offset(1, 8).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
End Sub
Is there a way to set the format of the totals to $#.## with the backround color of the cell and with a border around it?

Thanks, Glenn
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi again!

I've done a bit of macro recording and come up with this for ONE of the totals only!
Code:
Dim y As Range
    Set y = Range("B65536").End(xlUp)
    x.Offset(1, 6).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
    x.Offset(1, 6).NumberFormat = "$#.00"
    x.Offset(1, 6).HorizontalAlignment = xlCenter
    x.Offset(1, 6).Interior.ColorIndex = 15

    With x.Offset(1, 6).Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

    With x.Offset(1, 6).Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

    With x.Offset(1, 6).Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

    With x.Offset(1, 6).Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
Is there a way to simplify this please? :)

Cheers Glenn
 
Upvote 0
try
Code:
Dim y As Range
    Set y = Range("B65536").End(xlUp)
    With x.Offset(1, 6)
        .FormulaR1C1 = "=SUM(R2C:R[-1]C)"
        .NumberFormat = "$#.00"
        .HorizontalAlignment = xlCenter
        .Interior.ColorIndex = 15
        With .Borders
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
    End With
 
Upvote 0

Forum statistics

Threads
1,207,168
Messages
6,076,907
Members
446,239
Latest member
Home Nest

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