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
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