Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to sum using vba

I am trying to sum data within excel using VBA.

What I what is a script theat adds data together everytime a criteria is met
for example

Everytime cells(r,1) = "Band1" then i want to add cells(r,2)

Band 1 may appear 500 time in 750 rows so I want to add all teh 500 together

I am sure this is not to difficult but I am just a novice.

Marcus
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to sum using vba

simply:

Option Explicit
Function Counter() As Long
Counter = _
WorksheetFunction.SumIf(Range("C1:C25"), "Band1", Range("D1:D25"))
End Function

You can easily expand by passing the ranges and criteria as parameters.

"Mr M Walker" wrote:

I am trying to sum data within excel using VBA.

What I what is a script theat adds data together everytime a criteria is met
for example

Everytime cells(r,1) = "Band1" then i want to add cells(r,2)

Band 1 may appear 500 time in 750 rows so I want to add all teh 500 together

I am sure this is not to difficult but I am just a novice.

Marcus

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



All times are GMT +1. The time now is 10:21 PM.

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"