Make VBA DateDif behave and round down like Excel DATEDIFF

Randall Lee
DateDiff("m", "06/14/1982", "09,01,1982") = 3

A1 = 06/14/1982
A2 = 09/01/1982
=DATEDIF(A1, A2, "m") = 2

If I need DateDiff to round down like DATEDIF does, how do I accomplish this?

Ron Rosenfeld

You can use the Evaluate function in VBA. However, when working with dates in this manner, you need to ensure that the value being seen by the formula is the number corresponding to the date, and not a VBA Date data type. If the date is stored in a worksheet cell, you would do something like:

Evaluate("DATEDIF(" & [a1].Value2 & "," & [a2].Value2 & ", ""m"")")

If the dates are stored as dates in VBA variables, then:

Evaluate("DATEDIF(" & CDbl(DT1) & "," & CDbl(DT2) & ", ""m"")")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make mouse scrolling in Excel behave like Page Up/Page Down

From Dev

TableView - Attempting to make it behave like Excel

From Dev

Make DATEDIFF of Redshift behave as TIMESTAMPDIFF of MySQL

From Dev

Round function VBA EXCEL

From Dev

Excel DateDif() or =NETWORKDAYS()

From Dev

Excel VBA - Weekday and/or datediff function not working properly

From Dev

Make soft keyboard behave like IOS in Android

From Dev

Make an object behave like a module - Python 3

From Dev

Make eshell tab completion behave like Bash

From Dev

How to make UITextField behave like a UISearchBar in Swift?

From Dev

Make VIM cursor behave like Elvis

From Dev

Make asp:LinkButton behave like asp:button

From Dev

Android: make Recyclerview behave like LinearLayout

From Dev

Make a function behave like an instantiated EventEmitter

From Dev

Make multiple contenteditables behave like one document

From Dev

Is there a way to make a html list behave like this

From Dev

Make a shift key behave like an arrow key

From Dev

Make Image Button Behave Like a Toggle Button

From Dev

zsh completion: make sshrc behave like ssh

From Dev

How to make sub main behave like form?

From Dev

Make the contents of a div behave like a fixed background

From Dev

Make a selector behave like another in jQuery

From Dev

Excel VBA method ROUND is incorrect

From Dev

Like operator in Excel VBA

From Dev

Excel VBA like operator

From Dev

SQL LIKE in Excel vba

From Dev

Does DateDiff Round up?

From Dev

Does DateDiff Round up?

From Dev

DATEDIF in Excel Online for Office 365?