+ Reply to Thread
Results 1 to 2 of 2

Comparing dates in a worksheet

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    Chennai, India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Comparing dates in a worksheet

    Hi, I am writing a code in which the user enters 2 dates, start date and end date. There is a database workbook, where each worksheet represents a project. What I have to find out is the name of the projects whose starting date is more than start date that the user entered and the ending date is less than the end date.These project names should be displyed as result in another workbook, hyperlinked to the corresponding sheets in the datebase workbook.
    Following is the code that I wrote for that.
    Please Login or Register  to view this content.
    But this code is not working. Could someone please help me in this? Please

  2. #2
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: Comparing dates in a worksheet

    Vanakkam rinijg,

    unfortunately I can not really test your code, as I would need some sample data. Still your code is missing a "Next", as it contains a " For-next" loop. I assume it should be between those two End if at the end of your macro:

    Sub test()
    Dim date1 As Date
    Dim date2 As Date
    Dim start_date As Date
    Dim end_date As Date
    Dim starting As Range
    Dim finishing As Range
    If date1 = Null Or date2 = Null Then
    Else
    For Each sh In DestBook.Worksheets
    If sh.Range("B25").Value <= date1 And sh.Range("B26").Value >= date2 Then
    start_date = sh.Range("B25").Value
    end_date = sh.Range("B26").Value
    Set starting = sh.UsedRange.Find(What:=start_date, LookIn:=xlValues)
    Set finishing = sh.UsedRange.Find(What:=sh.Range("B26").Value, LookIn:=xlValues)
    shOutput.Hyperlinks.Add _
    Anchor:=shOutput.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0), _
    Address:=DestBook.FullName, _
    SubAddress:="'" & starting.Parent.Name & "'" & "!" & starting.Address, _
    TextToDisplay:=sh.Name
    Exit Sub
    End If
    Next
    End If
    End Sub

    Please let me know if this solves your issue

    Regards

    Theo

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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