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.
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"