Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum excel cells together using vba.

Status
Not open for further replies.

gjsala

Technical User
Feb 20, 2003
107
US
I'm looking to sum many excel cells together with the following code but instead of adding the cells together it only appends the numbers and giving a huge number for example 8.71201E+37
instead of 1507. What else can I use? Thanks in advance!

Do While Cells(r + 1, 2) <> ""
tmp1 = Cells(r,5)
tmpTotal = tmpTotal + tmp1
Loop

 


Why would you not use the spreadsheet SUM() function without a loop???
Code:
dim tmpTotal as single, r as long
Do While Cells(r + 1, 2).value <> ""
    if IsNumeric(Cells(r,5).value) then _
       tmpTotal = tmpTotal + Cells(r,5).value
    r = r + 1
Loop

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top