Results 1 to 6 of 6

Thread: Count no of cells containing date

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    You could try something like this

    Code:
    Sub kTest()
        
        Dim rngDate     As Range
        Dim CountDate   As Long
        
        Set rngDate = Range("a2:a" & Range("a" & Rows.Count).End(3).Row)
        
        With rngDate
            .Offset(, 1).EntireColumn.Insert
            .Offset(, 1).FormulaR1C1 = "=cell(""format"",rc[-1])"
            CountDate = Application.WorksheetFunction.CountIf(.Offset(, 1), "D*")
            .Offset(, 1).EntireColumn.Delete
        End With
        
    End Sub
    I see it doesn't with the format "dd-mmm-yy"
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by Admin View Post
    Hi,

    You could try something like this

    Code:
    Sub kTest()
        
        Dim rngDate     As Range
        Dim CountDate   As Long
        
        Set rngDate = Range("a2:a" & Range("a" & Rows.Count).End(3).Row)
        
        With rngDate
            .Offset(, 1).EntireColumn.Insert
            .Offset(, 1).FormulaR1C1 = "=cell(""format"",rc[-1])"
            CountDate = Application.WorksheetFunction.CountIf(.Offset(, 1), "D*")
            .Offset(, 1).EntireColumn.Delete
        End With
        
    End Sub
    I see it doesn't with the format "dd-mmm-yy"
    I am not sure why you wrote that last sentence as CELL("format",A1) will return "D1" for a cell formatted that way. HOWEVER, your code is not guaranteed to work as the OP wanted... see the EDIT NOTE that I added to my original message in this thread.

Similar Threads

  1. Replies: 5
    Last Post: 06-15-2013, 12:40 PM
  2. Count Colored Cells Using Excel Formula
    By mahmoud-lee in forum Excel Help
    Replies: 4
    Last Post: 06-15-2013, 11:37 AM
  3. automatic Add date in cells
    By Ryan_Bernal in forum Excel Help
    Replies: 1
    Last Post: 01-23-2013, 02:50 PM
  4. Replies: 0
    Last Post: 02-27-2012, 01:07 AM
  5. Lock cells on the basis of date VBA
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 22
    Last Post: 09-27-2011, 03:56 PM

Posting Permissions

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