PDA

View Full Version : SUM IF in vba and result in message box



arnab0711
02-02-2011, 06:57 PM
Hi,
I have this file with 3 sheets,on clicking enter you will get a userform that has two button which cleanses the data kept on inv sheet.Now the result is given on calcsheet.
Now I want the following of "Calc" sheet
1)=SUMIF(inv!AL:AL,"<13",inv!AK:AK)
2)=SUM(inv!AK:AK)
And the result of 1 divided by 2 will be shown as a message box at the click of button 3 on user form.

Bob Phillips
02-02-2011, 10:35 PM
tmp1 = Application.SumIf(Worksheets("inv").Range("AL:AL"), "<13", Worksheets("inv").Range("AK:AK"))
tmp2 = Application.Sum(Worksheets("inv").Range("AK:AK"))
MsgBox tmp1 / tmp2