+ Reply to Thread
Results 1 to 30 of 30

Selecting Quarter 1, Year 2014 Dates in ListBox

  1. #1
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello,

    I have a ListBox1 that is populated with Dates.

    I want to be able to assign a macro to a CommandButton that selects Quarter 1 dates for 2013. I wrote something like this:

    Please Login or Register  to view this content.
    It doesn't error, it just doesn't work. The code should select all values in the ListBox1 1/1/2013-3/31/2013

    I don't understand how to select a YEAR & MONTH to run through a loop and select.
    Attached Files Attached Files
    Last edited by EnigmaMatter; 03-07-2014 at 09:46 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello EnigmaMatter,

    There may be many reasons why this code is failing. To get an answer to this problem quickly, you should post a copy of your workbook.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Okay.

    I have attached an Example with the following code:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Edit: Workbook attached in first post.
    Last edited by stnkynts; 03-06-2014 at 06:30 PM.

  5. #5
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Yeah, I couldn't figure out how to attach it to my reply post.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello EnigmaMatter,

    The statement ListBox1.Selected(I) is a boolean value that tells you if the ListBox item was selected. Where do you want the Year, Month, and Day to go?

  7. #7
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello Leith Ross,

    I don't want it to go anywhere, I just want the button to select the dates 1/1/2013-3/31/2013.

    I will then execute a macro on all selected items.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello EnigmaMatter,

    The button's caption says "Select A1/1/2013-3/31/2013" and now you are saying you want the button to select these cells??? Can you explain step by step what the user is to do on this worksheet?

  9. #9
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    I apologize...the "A" in front of the caption is a typo.

    When the User presses the CommandButton...every selection choice from 1/1/2013 to 3/31/2013 will be selected in ListBox1. I want it to select the ListBox items not the Cells.

    Nothing else happens.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello

    This macro will compare the dates in the user has selected in column "A" and set the item in the ListBox if the dates match.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 03-06-2014 at 07:27 PM.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello EnigmaMatter,

    I just made a change to prevent an error if the user selects only a single cell. This version will prevent that from happening.
    Please Login or Register  to view this content.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    This will select the first quarter in 2013.

    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  13. #13
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Hello All,

    Thanks for the replies.

    I am trying Norie's solution...but when I adapt for my UserForm, it doesn't quite work.

    Please Login or Register  to view this content.
    Last edited by EnigmaMatter; 03-07-2014 at 09:07 AM.

  14. #14
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    I apologize for the multiple edits.

    The code above does in fact not work, though it does not error.
    Last edited by EnigmaMatter; 03-07-2014 at 08:44 AM.

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    How does it not work?

    Can you upload the file with the userform?

  16. #16
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Norie,

    Sure. Hang on, I need to make an Example file.

  17. #17
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    What is Listbox1 in this code?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Izandol

    Listbox1 was a listbox on a worksheet in the original attachment.

  19. #19
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    When I look before, code posted was:
    Please Login or Register  to view this content.
    It is different now.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    See what you mean now, didn't spot that myself.

  21. #21
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Norie, Izandol,

    I have posted an example Workbook that contains Norie's code to the original post.

  22. #22
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Why did you attach it to the original post?

  23. #23
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    I didn't realize I could post an attachment to any post. I am still learning my way around this forum, and forums in general.

    It's attached here now.
    Attached Files Attached Files

  24. #24
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    I think this is a date formatting problem.

  25. #25
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Can you expand on that?

  26. #26
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    You may try:
    Please Login or Register  to view this content.

  27. #27
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Izandol,

    This works in the example, and I will test in my UserForm later.

    Thanks to you, Norie, and everyone else who contributed.

  28. #28
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    It works in my UserForm!

    I just had to use this part with different object references:

    Please Login or Register  to view this content.
    I will be looking up CDate now...

  29. #29
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    Izandol

    When I try that code, and my own similar code, it seems like the date formatting isn't quite right - for me anyway

    For example, the next item after 12/1/2013 is 1/13/2013

    That's followed by 1/14/2013 and continues on in the same format up to 1/31/2013.

  30. #30
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Selecting Quarter 1, Year 2014 Dates in ListBox

    @Norie
    I too have this problem but I think OP is in USA so will not have it.
    For me I will do this:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Using SumProduct for dates inclusive of Year to Date, Month to date, Quarter to Date
    By cartica in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2014, 04:22 PM
  2. [SOLVED] Pivot Table Not Pulling 2014 Dates
    By Oscar Martin in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-13-2014, 11:24 AM
  3. Replies: 3
    Last Post: 01-30-2014, 08:19 PM
  4. [SOLVED] PIVOT TABLES: Grouping dates by Fiscal Year, Quarter and Month
    By bimmer5dude in forum Excel General
    Replies: 5
    Last Post: 06-30-2012, 09:13 PM
  5. StaticDate() Function shows year as 2014?
    By Samba1 in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 06-08-2010, 12:40 PM

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