-1

How do you sum a range in a sheet using vba.

I tried many different things but I can't figure it out. Thank you.

Sheet3.Sum...
Chrismas007
  • 6,085
  • 4
  • 24
  • 47
Dean
  • 63
  • 2
  • 9
  • Possible duplicate of: http://stackoverflow.com/questions/11707888/sum-function-in-vba – Chrismas007 Jul 08 '15 at 17:28
  • You can use many worksheet functions within VBA. e.g. `Dim dTotal as double: dTotal = Application.Sum(Range("A1:A9"))` . –  Jul 08 '15 at 17:39

1 Answers1

1

One method would be

Dim rng as Range
Dim lAnswer as Long

Set rng = sheets(1).Range("A1:A5")

lAnswer = application.WorksheetFunction.Sum(rng)

This works because application.WorksheetFunction creates a reference to all functions available within an excel sheet.

Grade 'Eh' Bacon
  • 3,773
  • 4
  • 24
  • 46