help with looping range and extracting value

  • Thread starter Thread starter Pb21
  • Start date Start date
P

Pb21

I want to sum the values in a range and have the following code:

Dim Total As Integer



For Each c In Worksheets("Error Codes").Range("T10:T45").Cells

Total = Total + c.Value

Next

ErrorCount = Total

I added a watch to c and the looping works or at least appears to ye
it wont extract a value despite the column t10 onwards having values.


Regards in advance for assistance.

Pete
 
Pb21 said:
I want to sum the values in a range and have the following code:

Dim Total As Integer



For Each c In Worksheets("Error Codes").Range("T10:T45").Cells

Total = Total + c.Value

Next

ErrorCount = Total

I added a watch to c and the looping works or at least appears to yet
it wont extract a value despite the column t10 onwards having values.


Regards in advance for assistance.

Peter
"extract a value"???

Alan Beban
 
Maybe you can just...

total = application.sum(Worksheets("Error Codes").Range("T10:T45"))
 
Your code works fine here, but it's an inefficient way of summing a
range.
Try something like this,
errorcount = Application.WorksheetFunction.Sum(Worksheets("Error
Codes").Range("T10:T45"))


Regards,
Vic Eldridge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top