Consulting

Results 1 to 4 of 4

Thread: Filter the microsoft date and time picker control output

  1. #1
    VBAX Newbie
    Joined
    Sep 2017
    Posts
    2
    Location

    Filter the microsoft date and time picker control output

    Hi

    Firstly I am a complete novice at VBA. I have used the Microsoft date and time picker control output to input dates into a column. I want to be able to filter that column using the filter function at the top. However every time I try to filter I get a pop-up with "runtime error 440 Invalid code value". I assume its because I have set specific cell values in the VBA code and filtering changes these values. This is the code I have used:

    Private Sub DTPicker21_CallbackKeyDown(ByVal  KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As  String, CallbackDate As Date)
    
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
      With Sheet1.DTPicker21
        .Height = 20
        .Width = 20
        If Not Intersect(Target, Range("G5:G3000,H5:H3000,I5:I3000")) Is Nothing Then
          .Visible = True
          .Top = Target.Top
          .Left = Target.Offset(0, 1).Left
          .LinkedCell = Target.Address
        Else
          .Visible = False
        End If
      End With
          
    End Sub
    Any Help with this would be much appreciated.

    Thanks
    Last edited by SamT; 09-27-2017 at 06:32 AM. Reason: Added Code formatting Tags with # Icon

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Can't reproduce that error here, but you could try adding the line:
    If Target.Cells.Count <> 1 Then Exit Sub
    straight after the 1st line (Private Sub Worksheet_SelectionChange(ByVal Target As Range)) to prevent a multiple-cell selection activating the DTPicker.
    Last edited by p45cal; 09-27-2017 at 08:11 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    You can try, as the first lines of the Procedure
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("G5:I3000")) Is Nothing Then exit sub
    Edit to add: Use the Worksheet_BeforeDoubleClick Event sub to eliminate the issue
    Option Explicit
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        if Intersect(Target, Range("G5:I3000")) Is Nothing then Exit Sub
    
        Cancel = True
        with Sheet1.DTPicker21
            .Height = 20
            .Width = 20
            .Visible = True
            .Top = Target.Top
            .Left = Target.Offset(0, 1).Left
            .LinkedCell = Target.Address
        end with
    End Sub
    Last edited by SamT; 09-27-2017 at 06:43 AM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Newbie
    Joined
    Sep 2017
    Posts
    2
    Location
    Thanks for your quick reply. P45cal that worked perfectly. Thanks you so much.

Posting Permissions

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