Checking for Dates in VBA

wakefield101

New Member
Joined
Jan 4, 2014
Messages
31
I am trying to make a button that says: If Date identified on row Q10:CA10 is less than Date in cell C6, then hide column(s), otherwise don't hide.

Some parameters:
Dates on row Q10:CA10
The Date format is: mmm-yy;@
Formula on cell Q10 is =EOMONTH($C$4,-1) & Formula on cells R10:CA10 --> not sure if this matters but wanted to tell you anyways

Dates in cell C6 is formatted: mmm-yy;@

Please let me know if you can assist with this code, I would greatly appreciate it.

If you can, please let me know if there is anything else that you need from me.

Thank you so very much!
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this:
Code:
Sub MyRowHideMacro()

    Dim cell As Range
    For Each cell In Range("Q10:CA10")
        If (cell.Value > 0) And (cell.Value < Range("C6").Value) Then
            Columns(cell.Column).EntireColumn.Hidden = True
        End If
    Next cell
    
End Sub
 
Last edited:
Upvote 0
Thanks for the help Joe!

However, the code is not working.... I am trying to play around with it as well but have any other thoughts??
 
Upvote 0
I had a typo. I had it looking at cell D6 instead of C6.

I just went back and edited my original post.
 
Upvote 0
Can you provide an example?
Specifically, what is in cell C6?
What value is not working and what column in row 10 is it?
 
Upvote 0
If the issue is that you also want it to possibly unhide rows that are already hidden too, just make this adjustment:
Code:
Sub MyRowHideMacro()

    Dim cell As Range
    For Each cell In Range("Q10:CA10")
        If (cell.Value > 0) And (cell.Value < Range("C6").Value) Then
            Columns(cell.Column).EntireColumn.Hidden = True
        Else
            Columns(cell.Column).EntireColumn.Hidden = False
        End If
    Next cell
    
End Sub
 
Upvote 0
So, overall when I click the button, nothing is working. There is no error with the code, there just isn't any effect being produced.....

It is difficult to say what is not specifically working since there isn't any error with your code.... I tried to use the code in both a regular button form and activex type...

Below is a sample of the model that I am working on... except that my columns go out to column CA...






Excel Workbook
BCDQRSTUVWXYZAAAB
6Study End Date*Aug-25************
7Current Month Close*Jan-16************
8Currency*USD************
9***************
10***************
11**Unit No.May-15Jun-15Jul-15Aug-15Sep-15Oct-15Nov-15Dec-15Jan-16Feb-16Mar-16Apr-16
12*11.2 a************
13*21.2.d************
SF Client Grid Unit Forecast
 
Upvote 0
I am trying to make a button that says: If Date identified on row Q10:CA10 is less than Date in cell C6, then hide column(s), otherwise don't hide.
Based on your example posted, you do not have a date in cell C6.
Ironically, you have a date posted in cell D6, which I accidentally posted my original code with.

Also none of the dates you posted in row 10 is less than your date in cell C6 (which is August 2025). So even if you updated the code to look at D6 instead of C6, it sill should not hide any columns anyway, based on your logic.
 
Upvote 0

Forum statistics

Threads
1,223,779
Messages
6,174,492
Members
452,567
Latest member
ONEIL290

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