+ Reply to Thread
Results 1 to 4 of 4

Case Statement and Dates

  1. #1
    Registered User
    Join Date
    12-08-2007
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    48

    Case Statement and Dates

    I have some VBA code that goes sort of like this (Excel 2016)

    Dim ccase as string

    ccase = me.cboCagatory
    Case Select
    Case cccase = One
    Me.txtDueDate = me.txtStartdate + 56
    Case ccase = two
    Me.txtDueDate = me.txtStartdate +14
    Case ccase = three
    Me.txtDueDate = me.txtStartdate +7

    etc#


    it si not exactly like this as I dont have the file on me but it appears the txtDueDate keeps coming out mm/dd/yyyy i have tried the format(me.txtDueDate, "dd/mm/yyyy" but it still dont work
    I would be most grateful for any advise as Dates appear to be a problem with Textboxes. I started with 30/12/2017 and with ccase one 56 is ok comes out 25/01/18 with ccase two comes out 14/01/2018 but with 7 it comes out 01/07/2018 not 07/01/2018 why?

    Many Many thanks

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Case Statement and Dates

    Try using the CDate function...
    Please Login or Register  to view this content.
    If that won't work you could use the split function to break up the text in txtStartdate using "/" as the separator, then build the date. That said, adding 56 days to december 30 2017 should not result in 25/01/2018? and ccase two should be the 13th of Jan?
    Last edited by Arkadi; 04-24-2018 at 02:57 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Case Statement and Dates

    This would be my suggestion:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-08-2007
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    48

    Re: Case Statement and Dates

    Thanks for your suggestions guys. I wish MS could put a date box feature instead of a text box.

+ 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] Select Case with multiple lines in a case statement?
    By jGKpZ8a33sPrnqX8fam7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2017, 10:25 AM
  2. [SOLVED] i have an if then statement that works, how to make it work as a with or case statement
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-03-2016, 03:34 PM
  3. Case statement VBA
    By marcvanderpeet12 in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2013, 05:30 PM
  4. Replies: 5
    Last Post: 07-19-2012, 02:53 AM
  5. A better Case (was "Create Loop with Case statement")
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2009, 12:55 PM
  6. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 PM
  7. Switch(case) statement(enhanced if statement)
    By zapopaul in forum Excel General
    Replies: 6
    Last Post: 10-24-2008, 06:53 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