Consulting

Results 1 to 12 of 12

Thread: Solved: Select Date Range

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location

    Solved: Select Date Range

    Hello,

    How do I have a user select a date range and have a msg box display number of hits?

    1. User Selects Date Range (combo box or txt box, doesn't matter)
    2. Script searches for date range within Excel (Col A)
    3. Msg Box Displays number of hits from user's input.

    Thanks in advance for the help.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The worst part of this is coding the selection of a date range. Why not just have the start and end dates in 2 cells and use

    =SUMPRODUCT(--(A2:A200>=B1),--(A2:A200<=B2))
    ____________________________________________
    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
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location
    Thanks. I will give that a try.

  4. #4
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location
    Quote Originally Posted by xld
    The worst part of this is coding the selection of a date range. Why not just have the start and end dates in 2 cells and use

    =SUMPRODUCT(--(A2:A200>=B1),--(A2:A200<=B2))
    How do I display my total in a message box?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You don't, it is already visible in the formula cell. If you have code, you could just read that cell's value.
    ____________________________________________
    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

  6. #6
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location
    Quote Originally Posted by xld
    You don't, it is already visible in the formula cell. If you have code, you could just read that cell's value.
    OK. Is there a way to show the results in a msgbox? That is what my boss wants.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes as I said. Assuming the formula is in C1

    [vba]

    MsgBox Range("C1").Value
    [/vba]
    ____________________________________________
    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

  8. #8
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location
    Quote Originally Posted by xld
    Yes as I said. Assuming the formula is in C1

    [vba]

    MsgBox Range("C1").Value
    [/vba]
    Thanks, it worked!!! I swear I tried that before. Anyway, thanks for the help.

  9. #9
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location
    Quote Originally Posted by xld
    Yes as I said. Assuming the formula is in C1

    [vba]

    MsgBox Range("C1").Value
    [/vba]
    I have one more question...

    We have different categories within our spreadsheet. Is it possible to group each category within the selected sumproduct?

    Example:

    User searches for a date range of 7/1/08 and 7/31/08
    Msgbox Output
    5 Violations:
    3 Not Closed
    2 Premature

    Thanks again.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this what you want?

    [vba]
    Select Case Range("C1").Value
    Case 5: Msgbox "Violations"
    Case 3: MsgBox "Not Closed"
    Case 2: MsgBox "Premature"
    End Select
    [/vba]
    ____________________________________________
    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

  11. #11
    VBAX Regular
    Joined
    Jul 2008
    Posts
    35
    Location
    Quote Originally Posted by xld
    Is this what you want?

    [vba]
    Select Case Range("C1").Value
    Case 5: Msgbox "Violations"
    Case 3: MsgBox "Not Closed"
    Case 2: MsgBox "Premature"
    End Select
    [/vba]
    I want the script to count the individual violations based on the date range the user selects. This is what I had in mind in terms of functions (probably wrong);

    Total Violations : 5 (MsgBox Range("F5").Value)
    Not Closed: 3 (countif(c:c,"Not Closed") Within date range selected)
    Premature: 2 (countif(c:c,"Premature") Within date range selected)

    Is this possible?

  12. #12
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Assuming that you can get your calculations correct in cells D1, D2,& D3. You could get the msgBox to display the values by

    [VBA]MsgBox "Total Violations :" & Range("D1").Value & vbCrLf & "Total Not Closed :" & Range("D2").Value _
    & vbCrLf & "Total Premature :" & Range("D3").Value[/VBA]

    Change the cell references to where ever you set your calculation results to be
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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