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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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