Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel macro, how to determine if a date is in the past?
    primarykey
    data
    text
    <p>Pardon the basicness of the question, but I figure there has to be a simple, naive solution to this that I just can't find.</p> <p>The basic scenario is that I have an Excel workbook that we use as our corporate solution for tracking backup success rates, and as a result, we have a number of sheets with the date in the first column, and some small macros to do calculations, based on whether the date is in the past or not. (Mainly for the managers who look at this sheet and don't want a bunch of empty rows, so the macros either hide or reveal the appropriate rows.)</p> <p>This has been working well until yesterday (happy new year); I assume because the macros are doing a string comparison, rather than a date comparison. (<code>01/01/2013</code> is smaller than <code>12/31/2012</code>, when viewed as strings.)</p> <p>The macros are below, and the question is essentially if there's a native way to compare dates in VBA, or if I need to convert the dates from a human date format into <code>yyyy/mm/dd</code> first, and then do my logic. (And if I do need to do so, a basic how would be nice - I try to avoid Excel and VBA in general where ever possible, so I'm extremely limited in my coding skills as far as VBA goes.)</p> <p><code>A2</code> would be the cell with the first date we started using this new version of the spreadsheet, and <code>A454</code> would be the last date I've bothered to extend the spreadsheet to, corresponding to the end of this year.</p> <pre><code>Sub ShowAll() Dim cell As Range For Each cell In Range("A2:A454") cell.EntireRow.Hidden = False Next End Sub Sub RevealPast() Dim cell As Range For Each cell In Range("A2:A454") If cell.Value &lt; Date Then cell.EntireRow.Hidden = False End If Next End Sub Sub HideFuture() Dim cell As Range For Each cell In Range("A2:A454") If cell.Value &gt;= Date Then cell.EntireRow.Hidden = True End If Next End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload