User Input date - Only Month and Year

jocker_boy

Board Regular
Joined
Feb 5, 2015
Messages
83
Hello,

I have this code, but i would like the user to only input date in this format: "mm/yy" and ignore entering the day. But i need to assume always day 01.
For example:

User insert: 10/22
And the date will appear: 01/10/22 (dd/mm/yy).

Thanks,
Gonçalo

VBA Code:
'Project Dates
    Dim strDate As String
    Dim LastMonth As Long
 
'Insert First Date
    strDate = InputBox("Insert start of the project (mm/dd/yy)", "Enter Date", Format(Date, "dd/mm/yy"))
 
    If IsDate(strDate) Then
        strDate = Format(CDate(strDate), "dd/mm/yy")
    Else
        MsgBox "Wrong date format"
    End If
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
@jocker_boy Does this help?

VBA Code:
'Project Dates
    Dim strDate As String
    Dim LastMonth As Long
 
'Insert First Date
    strDate = InputBox("Insert start of the project (mm/yy)", "Enter Date", Format(Date, "mm/yy"))
  
    
    strDate = "01/" & strDate
        If IsDate(strDate) Then
        'do whatever......
        MsgBox strDate & "  is good"
       
    Else
        MsgBox "Wrong date format"
    End If
 
Upvote 0
Solution
@jocker_boy Does this help?

VBA Code:
'Project Dates
    Dim strDate As String
    Dim LastMonth As Long
 
'Insert First Date
    strDate = InputBox("Insert start of the project (mm/yy)", "Enter Date", Format(Date, "mm/yy"))
 
   
    strDate = "01/" & strDate
        If IsDate(strDate) Then
        'do whatever......
        MsgBox strDate & "  is good"
      
    Else
        MsgBox "Wrong date format"
    End If
It's almost perfect.
But it's changing the day with month.

I enter "10/22" <- October/2022
But strDate appears: 10/01/22 (day ten of January of 2022) and i would like to appear 01/10/22 (day one of October of 2022).

Thanks,
Gonçalo
 
Upvote 0
I solve my issue:

VBA Code:
'Project Dates
    Dim strDate As String
    Dim LastMonth As Long
 
'Insert First Date
    strDate = InputBox("Insert start of the project (mm/yy)", "Enter Date", Format(Date, "mm/yy"))
 
    strDate = Format(CDate("01/" & strDate), "mm/dd/yy")

And i delete the if statement.
thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,935
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top