Date Issues, syntax, order, format

Showard27

Board Regular
Joined
Sep 5, 2005
Messages
155
Hi all

I am westling with a date issue in vba, I know it is to do with the way excel manipulates dates, but I just cant get there.

I derive two strings from a user form input, one is the month (selected from a list Jan to Dec) and the other a year in two digits (from a list from 15 to 25, meaning 2015 to 2025). So for example, the form passes "May" and "19"

When the proceedure runs is passes these two strings to a new proceedure where they are utilised in various ways however I need to also put the selected date in a column header in the format mmm-yy. However whichever way I try the underlying date ends up as 19/05/2019, rather than 01/05/19. The section of code that is offending is as follows. There are more lines than necessary as I have inserted extra to try and debug this, but at the point where the date is inserted in the cell at the last but one line, the date gets prefixed by 19 (in this case because I have selected 2019 on the user form)

I need the day to be set to 01 when it goes into the cell, even if the value is only displayed as mmm-yy. What am i doing wrong, any help gladly appreciated.

Code:
InMonth = DateValue("01/" & GMonth & "/20" & GYear)
    Debug.Print InMonth
       InMonthx = Month(InMonth)
    Debug.Print InMonthx
       newdate = "01/" & InMonthx & "/20" & GYear
    
    Debug.Print newdate
    Debug.Print Month(newdate)
    Debug.Print Format(newdate, "mmm-yy")
       InDate = Format(newdate, "mmm-yy")
          .Cells(1, LastCol + 1).Value = InDate
          .Cells(1, LastCol + 2).Value = "Total"
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try it like
Code:
   Range("A1").Value = DateValue("01/" & GMonth & "/20" & GYear)
   Range("A1").NumberFormat = "mmm-yy"
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,778
Members
449,336
Latest member
p17tootie

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