I am trying to total columns in code in Excel.
It worked untill I realized that Column8 on First Worksheet and Column8 on Second Sheet are totaling as well.
I need to figure out way to Name those Columns uniquely so WKbook does not total all Columns with the same name in Workbook.
I am counting lenght of the column in code as well so I know where to place Total row.
For s = 6 To 21
Set SumCol = Selection.QueryTable.ResultRange.Columns(s)
ExcelWK.Names.Add Name:=CStr("C" & xSheet & s), RefersTo:="=xSheet!column(s)" THIS PART HAS SYNTAX PROBLEM I THINK
SumRange = "C" & xSheet & s
' SumCol.Name = CStr(SumRange)
' SumRange = "C" & xSheet & s
' SumCol.Name = "Column" & s
SumCol.End(xlDown).Offset(2, 0).Font.Bold = True
SumCol.End(xlDown).Offset(2, 0).Formula = "=sum(SumRange)"
Next s
It worked untill I realized that Column8 on First Worksheet and Column8 on Second Sheet are totaling as well.
I need to figure out way to Name those Columns uniquely so WKbook does not total all Columns with the same name in Workbook.
I am counting lenght of the column in code as well so I know where to place Total row.
For s = 6 To 21
Set SumCol = Selection.QueryTable.ResultRange.Columns(s)
ExcelWK.Names.Add Name:=CStr("C" & xSheet & s), RefersTo:="=xSheet!column(s)" THIS PART HAS SYNTAX PROBLEM I THINK
SumRange = "C" & xSheet & s
' SumCol.Name = CStr(SumRange)
' SumRange = "C" & xSheet & s
' SumCol.Name = "Column" & s
SumCol.End(xlDown).Offset(2, 0).Font.Bold = True
SumCol.End(xlDown).Offset(2, 0).Formula = "=sum(SumRange)"
Next s