Results 1 to 2 of 2

Thread: Comparing dates in a worksheet

  1. #1

    Comparing dates in a worksheet

    Register for a FREE account, and/
    or Log in to avoid these ads!

    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.
     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
        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, _
            Exit Sub
            End If
    End If
    But this code is not working. Could someone please help me in this? Please

  2. #2
    Conjurer Roger Govier's Avatar
    Join Date
    Mar 2011
    Located near Abergavenny, South Wales, UK

    Can you upload a copy of your workbook, as this will make it easier to understand the problem.

    Roger Govier
    Microsoft Excel MVP

Posting Permissions

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