Consulting

Results 1 to 4 of 4

Thread: identify dates in a cell using macro

  1. #1

    Post identify dates in a cell using macro

    Hello There,

    I'm new to VBA in excel, I would like to identify the values in a range.

    Let me explain in detail...

    I have a column filled with various values,I need to copy the cells where the date is a future date, any date that is greater than the current date to a different workbook. I've managed to find out the way to copy date to different workbooks. However... I'm stuck when I have to identify if the date is a future date. Please help guys, I'm in urgent need of your help. Thanks.

    - Richard

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is there some difference between a future date and a date greater than the current date?

    [vba]

    If Range("A1").Value > Date Then
    'do something
    End If
    [/vba]

    Obviously you will need to incorporate intou your code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Post

    Thanks for the solution, However... Im still having issues.
    Can you give a sample sheet that I can look at.

    The Macro will copy and paste data to the next sheet if the value in Column A is a future date. Else it will do nothing.

    Thanks,

    Regards,
    Richard

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Try this:
    [VBA]Option Explicit

    Sub CopyDate()
    Dim cll As Excel.Range
    Dim rngDates As Excel.Range
    Dim wsOutput As Excel.Worksheet
    Dim dtVal As Date
    Dim dtNow As Date
    Dim lngRow As Long
    Set rngDates = Excel.Selection
    Set rngDates = Excel.Intersect(rngDates.Parent.UsedRange, rngDates)
    Set wsOutput = Excel.Workbooks.Add.Worksheets(1)
    dtNow = Date
    For Each cll In rngDates.Cells
    If IsDate(cll.Value) Then
    dtVal = CDate(cll.Value)
    If dtVal > dtNow Then
    lngRow = lngRow + 1
    wsOutput.Cells(lngRow, 1).Value = dtVal
    End If
    End If
    Next
    End Sub[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

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