How to get in a vbs script the sum of values of a Excel cells in a certain range?

C

Claudia d'Amato

Assume I want to get the sum of values of all cells from the range "H6:H18" from an Excel Worksheet.

How can I do this within vbs script?

Claudia
 
R

RyanH

This will definitely work for you.

Sub SumRange()

Dim myRange As Range
Dim cell As Range
Dim rngtotal As Double

Set myRange = Sheets("Sheet1").Range("H6:H18")

For Each cell In myRange
rngtotal = rngtotal + cell
Next cell

MsgBox "The Sum of Range(''H6:H18'') = " & rngtotal

End Sub

Hope it helps!
 
Top