PDA

View Full Version : Sum values



satyen
08-08-2011, 11:54 AM
Hello!

Been trying to figure out how I would go about this.

There is a figure in A1 on all sheets in a workbook. What is the most efficient piece of code to sum the values.

Much appreciated for any help in advance

Simon Lloyd
08-08-2011, 12:36 PM
Type =sum( then click the first tab and hold down shift and click your last tab, then choose the location of the figures to sum. So it looks like this:
=SUM(Sheet2:Sheet3!A1)

satyen
08-08-2011, 12:47 PM
Cheers Simon. What would be the VBA equivalent?

Kenneth Hobs
08-08-2011, 01:11 PM
'=SummAllA1("Sheet1")
Function SumAllA1(sName As String) As Double
Dim ws As Worksheet, d As Double
Application.Volatile True
For Each ws In Worksheets
If ws.Name <> sName Then d = d + ws.Range("A1").Value2
Next ws
SumAllA1 = d
End Function