Results 1 to 4 of 4

Thread: help with dates in VBA
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Mar 2016
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default help with dates in VBA

    I'm relativity new to VBA. I am hopeful someone can help me with the below macro.

    The Macro takes a day of the week like Monday or Tuesday and converts it to a real date based on whats imputed.

    It works the way I want other than, I need it to be formatted as a 2 digit month 2 digit day and 4 digit year.
    Example January 7th 2019 would be 01/07/2019.

    Thanks for any help!!








    Sub InputboxStuff()
    Dim dte As Date
    mbox = InputBox("Enter a Monday Date")
    If IsDate(mbox) Then
    dte = CDate(mbox)


    Else
    MsgBox "This isn't a date. Try Again"





    End If




    Dim c As Range
    For Each c In Selection
    Select Case UCase(c)


    Case "MONDAY"
    c = dte
    Case "TUESDAY"
    c = dte + 1


    Case "WEDNESDAY"
    c = dte + 2


    Case "THURSDAY"
    c = dte + 3


    Case "FRIDAY"
    c = dte + 4


    End Select
    Next c






    End Sub

  2. #2
    MrExcel MVP
    Join Date
    May 2009
    Posts
    16,590
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    9 Thread(s)

    Default Re: help with dates in VBA

    Add the line in red font to each case.
    Code:
    Case "MONDAY"
    c = dte
    c.NumberFormat = "mm/dd/yyyy"
    
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

  3. #3
    New Member
    Join Date
    Mar 2016
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help with dates in VBA

    Awesome!
    This works great thanks!

  4. #4
    MrExcel MVP
    Join Date
    May 2009
    Posts
    16,590
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    9 Thread(s)

    Default Re: help with dates in VBA

    Quote Originally Posted by bbrimberry View Post
    Awesome!
    This works great thanks!
    You are welcome - thanks for the reply.
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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