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:

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
Office Version
  1. 365
Platform
  1. Windows
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:

wakefield101

New Member
Joined
Jan 4, 2014
Messages
31
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??
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
Office Version
  1. 365
Platform
  1. Windows
I had a typo. I had it looking at cell D6 instead of C6.

I just went back and edited my original post.
 

wakefield101

New Member
Joined
Jan 4, 2014
Messages
31

ADVERTISEMENT

Yeah, I caught that... but it is still not working...
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
Office Version
  1. 365
Platform
  1. Windows
Can you provide an example?
Specifically, what is in cell C6?
What value is not working and what column in row 10 is it?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
 

wakefield101

New Member
Joined
Jan 4, 2014
Messages
31
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
 

wakefield101

New Member
Joined
Jan 4, 2014
Messages
31
I have a separate button that unhides columns. I need this button to only hide the columns...
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,005
Messages
5,526,232
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top