PDA

View Full Version : Excel:VB Sum up value in specific field



man
01-10-2011, 11:01 AM
Hi all
I am fresh in VB
If I want to design a VB to sum the value only for "D", (refer to attachment), how could I design the VB?

Sean.DiSanti
01-10-2011, 11:18 AM
if you wanted to do it without VB, you could use the SUM(if()) array formula...in this case it would be
=SUM(IF((c3:c8="D"),b3:b8,0))
and make sure after entering, that you finished editing the formula by pressing control+shift+enter

Bob Phillips
01-10-2011, 11:22 AM
Sean! No need for an array formula

=SUMIF(C3:C8,"D",B3:B8)

Sean.DiSanti
01-10-2011, 11:26 AM
nice, i've been using the Sum(if()) forever and that one is a lot quicker

man
01-11-2011, 01:21 AM
if i want to use VB and sum all "D" . "M", "L" 's value, how can I do it?
Thx

Bob Phillips
01-11-2011, 01:32 AM
Public Function SumDepends(critRange As Range, crit As Variant, sumRange As Range)

SumDepends = Application.Sumif(critRange, crit, sumRange)
End Function