Sumif with dates

Natit

Board Regular
Joined
Jan 22, 2012
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hi,
I want to sum the cells in Column A in condition that the date in Column B is later than 1/1/2016.
I need it for VBA because I'm running this on 100 sheets.
TIA
Nati
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try
Somewhere put =SumDate(A1:B14;"1/1/2016")
Adjust the range to your need
Code:
Option Explicit
Function SumDate(WkRg As Range, WkDate As Date) As Double
Dim Rg  As Range
    For Each Rg In WkRg.Columns(1).Cells
        If (Rg.Offset(0, 1) < WkDate) Then SumDate = SumDate + Rg
    Next Rg
End Function
 
Upvote 0
I thought there is a simple SUMIF option' to save the loop
 
Upvote 0
Just curious how this works as a VB. I use SUMIFS all the time with multiple columns /rows and nest several. If I did VB how does it execute ? I guess it’s all programmed
 
Upvote 0
there is a simple SUMIF option' to save the loop
Yes of course
Code:
Function SumDate1(WkRg As Range, WkDate As Date) As Double
Dim Rg  As Range
    SumDate1 = Application.SumIf(WkRg.Columns(2).Cells, "<1/1/2016", WkRg.Columns(1).Cells)
End Function
 
Upvote 0

Forum statistics

Threads
1,216,500
Messages
6,131,016
Members
449,615
Latest member
Nic0la

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