VBA SumIFs not working whilst SumIF with same arguments does

pvans267

New Member
Joined
Feb 25, 2010
Messages
35
Good afternoon,

I hope someone can help me with this. I am trying to build a SumIfs formula in VBA. I have tested this formula in the worksheet by hardcoding it and it works - but when I enter the formula in VBA, I get the error: "Run-time Error '1004': Unable to get the SumIfs property of the WorksheetFunction class.'

My ranges I have also tested individually (using simple for loops to see that I am getting the correct range of values) and if I create a simple SumIf calculation using the same ranges, it works.

My formula is as follows:

Code:
vDate1 = Worksheets("Sheet1").Range("A2")        ' value is 24/12/2016

Set rngInputsDivisionColumn = Worksheets("Sheet1").Range("C21:C26")
Set rngInputsYearColumn = Worksheets("Sheet1").Range("D21:D26")
Set rngInputsIncomeColumn = Worksheets("Sheet1").Range("G21:G26")

vProfit = Application.WorksheetFunction.SumIfs(rngInputsIncomeColumn , rngInputsYearColumn , ">=" & (Year(vDate1)-3))
' Further condition of which division will be added once I can get the formula working
' This expression doesn't work

vProfitAlt = Application.WorksheetFunction.SumIf(rngInputsYearColumn , ">=" & (Year(vDate1)-3), rngInputsIncomeColumn)
' This formula does work.  Even though I am using the same ranges and conditions as above

It is certainly possible that I am making an incredibly obvious and foolish mistake... but for the life of me, I can't see where.

Please could someone suggest what could be going wrong.

If it helps, here is the table of values on the sheet

CDEFG
Drinks201410000
Drinks201510000
Drinks201610000
Tickets2014500
Tickets2015500

<tbody>
</tbody>

I hope I have been as clear as possible, if not, let me know and i will add as much information as I can

Thank you in advance

Paul
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Nevermind, I was being foolish. Due to NULL values in my real data column G, the ranges were of different sizes. Hence the failure.

Still interesting that the SumIf worked even with the different sized ranges... but I guess that is a completely different discussion.

Kind regards,
 
Upvote 0

Forum statistics

Threads
1,215,906
Messages
6,127,660
Members
449,395
Latest member
Perdi

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