Hide rows based on Datediff

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
164
Office Version
  1. 365
Platform
  1. Windows
I need some help combining both. I have two cells where dates are entered, so if the difference between both dates is greater than 6 months then rows 71:73 unhide......
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this while on the sheet in question where the dates are in cells A2 and B2 (change to suit):

Code:
Option Explicit
Sub Macro3()

    If Evaluate("DATEDIF(A2,B2,""M"")") > 6 Then
        Application.ScreenUpdating = False
            Rows("71:73").Hidden = False
        Application.ScreenUpdating = True
    End If

End Sub

HTH

Robert
 
Upvote 0
Unfortunately it didn't work.....do the dates have to be in a specific format? I presently have the dates as yyyy-mm-dd

I also tried this but nothing

Sub Macro3()
If Evaluate("DATEDIF(H68,K68,""M"")") > 6 Then
Worksheets("Sheet1").Range("73:75").EntireRow.Hidden = True
Else
Worksheets("Sheet1").Range("73:75").EntireRow.Hidden = False
End If
End Sub
 
Last edited:
Upvote 0
The code you posted works fine for me.

Do you get any errors (if yes what exactly does it say)?
Is the date in H68 before the date in K68?
If you put in empty cells the formulas
=ISNUMBER(H68)
and
=ISNUMBER(K68)
do you get TRUE or FALSE for the results of both formulas?
Are H68 and K68 both on Sheet1 and is Sheet1 active when running the code?
 
Upvote 0
H68 has an earlier date than K68.....and they are both on Sheet1 which is the active sheet
 
Upvote 0
....and the answer to the other 2 questions is......?
 
Upvote 0
What the 2 formulas produce no and not TRUE or FALSE?
 
Upvote 0
I just got it to work.....inserted the macro in another sub that was doing other hiding functions

thank you
 
Upvote 0
encountered another problem ....how can get the datedif to calculate > 6 months exactly base on the days and the month.

example: 2108-04-15 and 2018-10-27.....I need that to trigger greater than 6 months. Right now it only calculates based on the month
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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