Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with looping range and extracting value


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

--
Pb2
-----------------------------------------------------------------------
Pb21's Profile: http://www.excelforum.com/member.php...fo&userid=1539
View this thread: http://www.excelforum.com/showthread.php?threadid=27011

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default help with looping range and extracting value

Pb21 wrote:

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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default help with looping range and extracting value

Maybe you can just...

total = application.sum(Worksheets("Error Codes").Range("T10:T45"))



Pb21 wrote:

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

--
Pb21
------------------------------------------------------------------------
Pb21's Profile: http://www.excelforum.com/member.php...o&userid=15398
View this thread: http://www.excelforum.com/showthread...hreadid=270110


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default help with looping range and extracting value

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


Regards,
Vic Eldridge


Pb21 wrote in message ...
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping thru a range of cells COBOL Dinosaur New Users to Excel 9 June 2nd 07 03:41 AM
looping across columns in range? Amy Excel Discussion (Misc queries) 3 July 19th 05 08:01 PM
Looping through a range of cells rEN Excel Programming 4 June 10th 04 06:28 PM
Need help with looping through a dynamic range TBA[_2_] Excel Programming 3 December 14th 03 01:54 PM
looping through a range Jo[_6_] Excel Programming 1 October 21st 03 11:11 PM


All times are GMT +1. The time now is 07:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"