Sum all values using IF function

  • Thread starter Thread starter girth69
  • Start date Start date
G

girth69

I have a list full of information on my sheet. One column displays a
department number and another column displays a number of hours that
this department has worked.

I need to sum together all the hours of a certain department to get an
overall total.

e.g.

Dept Number Number of Hours
151 4
151 4
151 1
132 6
132 2
151 4
144 8
144 3
132 1

How do i sum all the numbers of hours for department 151?? im assuming
its an IF statement??
 
Hi there

Try this ,it may be helpful though not so good looking

Sub sumfig()
Dim r as integer
Dim s as integer
For r= 1 to 9 (kt's the number of departments)
if cells(r,1).value = 151 then
s=s+cells(r,2).value
endif
next
' to show the result of sum of the hours
cells (12,1).value =s
end sub
 
Back
Top