ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to get in a vbs script the sum of values of a Excel cells in a certain range? (https://www.excelbanter.com/excel-discussion-misc-queries/192772-how-get-vbs-script-sum-values-excel-cells-certain-range.html)

Claudia d'Amato

How to get in a vbs script the sum of values of a Excel cells in a certain range?
 
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


RyanH

How to get in a vbs script the sum of values of a Excel cells in a
 
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!
--
Cheers,
Ryan


"Claudia d'Amato" wrote:

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



Gord Dibben

How to get in a vbs script the sum of values of a Excel cells in a
 
This looks like VBA.

Doesn't OP want vbscript?


Gord Dibben MS Excel MVP

On Thu, 26 Jun 2008 10:58:00 -0700, RyanH
wrote:

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!




All times are GMT +1. The time now is 01:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com