Using Sumifs in VBA

Hazelwood

New Member
Joined
Feb 25, 2018
Messages
13
I'm struggling to create a sumifs in VBA - i can easily create it in a cell but want to be able able to use it in VBA

I have my code below with my sumifs statement written in theory, could someone help me to put together the sumifs statement properly and the proper Dim and Set qualifiers


Sub TotalUsingSumifs()


' Worksheet is Person's Pay
' My Table is called Table1 - (it is in Person's Pay)


' Table 1 has the following columns (I'll Name the headers)
' Dates - (dates the regular pay was paid on)
' Regular - (numeric pay column)


' My code to get the start and end dates for my criteria


Dim BeginDate As Date
Dim EndDate As Date


PayDate = Date
YearOfPay = Year(PayDate)


BeginDate = DateSerial(YearOfPay, 1, 1)
EndDate = DateSerial(YearOfPay, 12, 31)




' I don't know how to create the sumifs statement to do the following


RegTotal = SumIfs(Regular, Dates, ">=" & BeginDate, Dates, "<=" & EndDate)


' I'm using Regular as my column to sum
' I'm using Dates as my column criteria
' I'm using the criteria ">=" & BeginDate as the 1st day of the year
' I'm using the criteria "<=" & EndDate as the last day of the year
' I want the regular pay for a specific year


End Sub


Thank you in advance ... Hazelwood

 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Perhaps add WorksheetFunction. before SumIfs, like so:

RegTotal = WorksheetFunction.SumIfs
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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