vba re-creates total row?

gino59

Active Member
Joined
Jul 26, 2010
Messages
496
Hi folks! I have some code which updates an account worksheet from a master account sheet. I've set it up to write the specific data to an Excel 2007 table. I want the table to show a total row. The code keeps "adding" a new total row every time the account is updated. I just want ONE total row!!! :)

Any ideas?
Many thanks!!
Gino

Code:
Sub UpdtAccts()
'    *********************************************************************************
'    This procedure updates the individual Account worksheets with data entered into
'    the mData table located on the mData worksheet.
'
Dim LR As Long
'
'    *********************************************************************************
'    Acct1 TRANSACTIONS UPDATE
     Application.ScreenUpdating = False
     Sheets("mData").Activate
     ActiveSheet.ListObjects("mData").Range.AutoFilter Field:=4, Criteria1:= _
          "Acct1"
     Range("mData[[DATE]:[DEPOSIT]]").Select
     Selection.Copy
     'Worksheets("Acct1").Visible = xlSheetVisible
     Application.Goto Reference:=Worksheets("Acct1").Range("A2")
     ActiveSheet.ListObjects("Acct1tbl").Unlist
     ActiveSheet.Paste
     LR = Cells(Rows.Count, "A").End(xlUp).Row
     Range("A1").Activate
          ActiveSheet.ListObjects.Add(xlSrcRange, Range("$a$1:$m" & LR), , _
              xlYes).Name = "Acct1tbl"
          ActiveSheet.ListObjects("Acct1tbl").ShowTotals = True
          Range("Acct1tbl[#All]").Select
          With Selection
               .Font.Name = "Calibri"
               .Font.Size = 10
               .Font.Bold = True
               .Columns.AutoFit
          End With
'    Set the Balance Column formulas.
     Range("M3").Activate
     ActiveCell.FormulaR1C1 = _
        "=SUM(R[-1]C+Acct1tbl[[#This Row],[DEBIT]]-Acct1tbl[[#This Row],[DEPOSIT]])"
     Range("M4").Activate
     Range("Acct1tbl[BALANCE]").FormulaR1C1 = _
        "=SUM(R[-1]C+Acct1tbl[[#This Row],[DEBIT]]-Acct1tbl[[#This Row],[DEPOSIT]])"
     Range("M2").Activate
     ActiveCell.FormulaR1C1 = _
        "=SUM(Acct1tbl[[#This Row],[DEBIT]]+Acct1tbl[[#This Row],[DEPOSIT]])"
'    Set the current value of this account.
     Range("Acct1tbl[[#Totals],[BALANCE]]").Select
     ActiveCell.FormulaR1C1 = "=OFFSET(Acct1tbl[[#Totals],[BALANCE]],-1,0)"
     Range("Acct1tbl[#Totals]").Select
          With Selection.Font
               .ThemeColor = xlThemeColorDark1
               .TintAndShade = 0
          End With
          With Selection.Interior
               .Pattern = xlSolid
               .PatternThemeColor = xlThemeColorAccent1
               .ThemeColor = xlThemeColorAccent1
               .TintAndShade = 0
               .PatternTintAndShade = 0.799981688894314
          End With
End sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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