Replace SUMIF, not calculating

CRVerdusco

New Member
Joined
Nov 22, 2013
Messages
6
I have a sheet that is a master billing for 4 properties. The sumif is used to create a subtotal for each column with a row for each property. in column B user puts in a property code that is the constant in a sumif. Is there a way to do this with out sumif. The issue I am having is that it doesn't update properly. I can calculate it and everything works but when you open the workbook it shows incorrect values.

Code:
'Calculates Totals for Westport Conference Center
Public Function TotalWCC(Subtotal As Range)

    TotalWCC = WorksheetFunction.SumIf(Range("B4:B80"), WPConf, Subtotal)
End Function
'Calculates Totals for Westport Plaza
Public Function TotalWP(Subtotal As Range)
    TotalWP = WorksheetFunction.SumIf(Range("B4:B80"), WPPlaza, Subtotal)
End Function
'Calculates Totals for Westport Sheraton Chalet
Public Function TotalCH(Subtotal As Range)
    TotalCH = WorksheetFunction.SumIf(Range("B4:B80"), WPChalet, Subtotal)
End Function
'Calculates Totals for DoubleTree Westport
Public Function TotalDTW(Subtotal As Range)
    TotalDTW = WorksheetFunction.SumIf(Range("B4:B80"), WPDblTree, Subtotal)
End Function
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You could use =sumproduct() instead of sumif().

Sumproduct multiplies, then sums. So the formula would look something like...

=sumproduct(b4:b80,--(WPConf="XXXX"))

Where XXXX would be the property code for the Westport Conf. Ctr.
 
Upvote 0
Thank you for your response, can you elaborate more on how this would work. I would also prefer to have this as a user function for usability reasons.

Currently WPConf is a public const that I called from another module. b4:b80 is where excel looks for the property code and then it should pull values from "subtotal" which is a range inputted into the user defined function.

based on your suggestion and research into INDEX I was trying the following but get #VALUE error

Code:
Public Function TotalDTW(Subtotal As Range)

TotalDTW = WorksheetFunction.SumProduct((("$b$4:index($b:$b, counta($b:$b))") = WPDblTree) * Subtotal)
End Function
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top