+ Reply to Thread
Results 1 to 5 of 5

Coding Help - CDate & "Greater Than" Date

Hybrid View

  1. #1
    Registered User
    Join Date
    08-04-2015
    Location
    United Kingdom
    MS-Off Ver
    MS 2010
    Posts
    4

    Coding Help - CDate & "Greater Than" Date

    Hi All,

    Firstly thanks for taking the time and reading my post.

    I've got an excel file full of data and Column "E" contains multiple dates. The user inputs the specified date and then I would like the VBA program to count the number of times this date and any exceeding dates appear.

    For example User Input "20/01/2015", I'd like the amount of times "20/01/2015", "21/01/2015", "22/01/2015"....+N

    I've tried to use the code below to achieve this and I cannot get the greater than symbol to work! The file will calculated everything up to the first date on the spreadsheet, i.e. the 19/01/2015 but when it reaches the 20th it pulls back 0 results

    Thanks for any constructive feedback,


    Sub ColumnData()

    Dim InputDate As Date

    InputDate = InputBox("Enter Key Date", (CDate(InputDate)))

    MsgBox ("The Value is " & InputDate)

    'Function to Countif (DATES)
    Range("C1").End(xlDown).Offset(1, 0).Formula = Application.WorksheetFunction.CountIf(Range("G3:G50"), ">" & InputDate)

    End Sub

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Coding Help - CDate & "Greater Than" Date

    Welcome too the Forum. Please use code tags when posting. See Forum Rule No. 3 on the link.

    http://www.excelforum.com/forum-rule...rum-rules.html

    Maybe:

    Sub ColumnData()
    
    Dim InputDate As Date, x As Long, y as Long
    x = 0
    
    InputDate = InputBox("Enter Key Date", (CDate(InputDate)))
    
    MsgBox ("The Value is " & InputDate)
    
    For y = 3 to 50
      If cells(i,"G") => InputDate then x = x+1
    Next y
    
    Range("C1").End(xlDown)(2) = x
    
    End Sub
    Last edited by JOHN H. DAVIS; 08-04-2015 at 11:02 AM.

  3. #3
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Coding Help - CDate & "Greater Than" Date

    Is there a reason why the formula has to be in all of the cells? Is it not just a single cell formula?
    =COUNTIF(G:G,">=" & InputDate)
    If someone has helped you then please add to their Reputation

  4. #4
    Registered User
    Join Date
    08-04-2015
    Location
    United Kingdom
    MS-Off Ver
    MS 2010
    Posts
    4

    Re: Coding Help - CDate & "Greater Than" Date

    Thanks for the replies. I will follow the rules from now on. I managed to get the following to work:

     Sub ColumnData()
        '">" & CDbl(InputDate),
        Dim InputDate As Date
      
        InputDate = InputBox("Enter Key Date")
          
        'Function to Countif (TEST)
        MsgBox CDate(InputDate)
        'Function to Countif (DATES)
        Range("C1").End(xlDown).Offset(1, 0).Formula = Application.WorksheetFunction.CountIf(Range("G3:G50"), ">" & CDbl(InputDate))
        End Sub
    I would like to add another 'IF' statement to this so I adapted the line of code to the following

    Range("C1").End(xlDown).Offset(1, 0).Formula = Application.WorksheetFunction.CountIfs(Range("G3:G50"), ">" & CDbl(InputDate), Range("E1:E20"), "X1")
    I now recieve the dreaded Run-time error '1004': Unable to get the countifs property of the WorksheetFunction class. Any ideas where I am going wrong?

    Thanks

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Coding Help - CDate & "Greater Than" Date

    The ranges in COUNTIFS need to be the same size.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 09-20-2014, 07:10 AM
  2. [SOLVED] IF Formula not working - need to return "NO" if cell is 1% greater or "YES" if less 1%
    By maryren in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-26-2013, 11:34 AM
  3. [SOLVED] Cell Formula to count time with "Greater Than or Equal to" and "Less Than"
    By chriswhite1982 in forum Excel General
    Replies: 3
    Last Post: 06-16-2013, 12:30 AM
  4. Value if "Today" greater than stated Date
    By knowtrump in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-17-2013, 02:37 PM
  5. Using DMIN to evaluate "less than" or "greater than" a specific date
    By williams485 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-01-2012, 12:45 PM
  6. Colour coding a cell which is "out of date"
    By mcslide in forum Excel General
    Replies: 2
    Last Post: 07-05-2012, 11:23 AM
  7. Replies: 2
    Last Post: 03-11-2006, 04:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1