Application.WorksheetFunction.SumIfs beetween dates

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

Something is getting wrong in the following operation:

VBA Code:
Cells(4, 5) = Application.WorksheetFunction.SumIfs(rnglav.Offset(0, 8), rnglav, "LONDON", rnglav.Offset(0, 12), "0", rnglav.Offset(0, 30), ">=" & startdate, rnglav.Offset(0, 30), "<=" & enddate)

The result is nothing (no errors, no "0").

The problem should be the dates management.

In my macro I have:
Code:
Dim startdate As Double, enddate As Double

In the column rnglav.Offset(0, 30) I have the dates in format number

Code:
rnglav.Offset(0, 30).NumberFormat = "0"

Any ideas?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
The problem could be in what you posted but is more likely in your data. It is not possible to diagnose this without knowing all the values that are referenced in the formula, and how you are setting startdate and enddate and what their values are.
 
Upvote 0
The problem could be in what you posted but is more likely in your data. It is not possible to diagnose this without knowing all the values that are referenced in the formula, and how you are setting startdate and enddate and what their values are.

Removing the part referenced to the dates, the sum is correctly performed, but it is not narrowed to the period I need.
 
Upvote 0
At the point where this line of code is executed what are the values of:

rnglav.Offset(0, 30)
startdate
enddate
 
Upvote 0
At the point where this line of code is executed what are the values of:

rnglav.Offset(0, 30)
startdate
enddate

Before the line

VBA Code:
rnglav.Offset(0, 30).NumberFormat = "0"

the values are:

startdate 43800 Double
enddate 43830 Double

rng.offset(30) values in format date dd/mm/yyyy, example: 04/12/2019
 
Upvote 0
This is difficult without access to your data. How is rnglav defined?
 
Upvote 0
Code:
Dim lrlav As Long, rnglav As Range
        lrlav = Worksheets(1).Cells(Rows.Count, "B").End(xlUp).Row
                   Set rnglav = Worksheets(1).Range("B2:B" & lrlav)

It is defined this way.
 
Last edited:
Upvote 0
The only thing I can think of is that either your code is looking in the wrong column for the dates, or the dates in that column are text instead of date values.

Are your dates in column AF? Are they Excel date values, not strings?

Do you have access to a site where you can post the file?
 
Upvote 0

Forum statistics

Threads
1,215,546
Messages
6,125,459
Members
449,228
Latest member
moaz_cma

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