Sort Date with Drop Down

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort Date with Drop Down

Post by HansV »

Try

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
  Dim oCell As Range
  If Not Intersect(Range("C:K"), Target) Is Nothing Then
    For Each oCell In Intersect(Range("C:K"), Target)
      If oCell.Value = "" Then
        oCell.Borders(xlEdgeBottom).LineStyle = xlLineStyleNone
      Else
        oCell.Borders(xlEdgeBottom).LineStyle = xlDot
      End If
    Next oCell
  End If
End Sub
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Sort Date with Drop Down

Post by adam »

Thanks for the code. It does suit my needs. But. how shall I alter the code with the following with it?

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Range("C11:C" & Rows.Count), Target) Is Nothing Then
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Range("AllDates").AdvancedFilter _
      Action:=xlFilterCopy, CriteriaRange:="", _
      CopyToRange:=Sheets("StaffList").Range("C1"), Unique:=True
 End If
Static runme As Boolean
If runme = False And Target.Column = 5 And Target.Row >= 11 Then
    runme = True
    Target.Offset(, -2).Value = Date
     Target.Offset(, -1).Value = Time()
Else: runme = False
End If
  If Target.Column = 8 And Target.Row >= 11 Then
        Target.Offset(, 1).Formula = "=IF(DATEDIF(RC[-1],NOW(),""y"")>0,DATEDIF(RC[-1],NOW(),""y"") & "" Years"",IF(DATEDIF(RC[-1],NOW(),""m"")>0,DATEDIF(RC[-1],NOW(),""ym"") & "" Months"",DATEDIF(RC[-1],NOW(),""y"")))"
             Application.EnableEvents = True
       Application.ScreenUpdating = True
    End If

End Sub
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sort Date with Drop Down

Post by HansV »

Just add the code that I posted (but of course without the Private Sub ... and End Sub lines) to the code that you have, for example above End Sub.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Sort Date with Drop Down

Post by adam »

Thanks for the reply.
Best Regards,
Adam