Michele317
New Member
- Joined
- Apr 29, 2024
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
Hello,
I'm facing the following problem:
I insert in 2 cells: month (in text) and year (in number) (example. "October" and "2024").
I want to create a function that convert this information in the following format "dd/mm/yyyy" and print it into a specific cell.
I tried myself for a lot of time and I'm having some issue:
Range("B3").NumberFormat = "General"
Sheets(Worksheets.Count).Range("B3").Value = CStr("01/" & ConvertMonth(month) & "/" & year)
'I also tried using
Sheets(Worksheets.Count).Range("B3").Value = Format("01/" & ConvertiMese(mese) & "/" & anno, "dd/mm/yyyy")
both ways are useless. It still convert the month into the day and so the result is 10/01/2024, where 10 are the days
where ConvertMonth is:
Select Case testoMese
Case "Gennaio"
ConvertiMese = "01"
Case "Febbraio"
ConvertiMese = "02"
Case "Marzo"
ConvertiMese = "03"
Case "Aprile"
ConvertiMese = "04"
Case "Maggio"
ConvertiMese = "05"
Case "Giugno"
ConvertiMese = "06"
Case "Luglio"
ConvertiMese = "07"
Case "Agosto"
ConvertiMese = "08"
Case "Settembre"
ConvertiMese = "09"
Case "Ottobre"
ConvertiMese = "10"
Case "Novembre"
ConvertiMese = "11"
Case "Dicembre"
ConvertiMese = "12"
End Select
If you have any suggestion or way to also improve the code, you are more than welcome :D
Thank you
I'm facing the following problem:
I insert in 2 cells: month (in text) and year (in number) (example. "October" and "2024").
I want to create a function that convert this information in the following format "dd/mm/yyyy" and print it into a specific cell.
I tried myself for a lot of time and I'm having some issue:
- Note: the months are written in italian (so, I don't have "October" but "Ottobre") (I'm saying this if this could interfer in some way with excel or vba)
- Note: I modified the system date to "1904" since I need to do calculation with time and I might end up having negative times (I'm saying this if this could interfer in some way with excel or vba)
- What I'm having as result is the following: 10/01/2024, where 10 is the day. So it is taking what should be the month written in number and coverting it into days
- Above the code:
Range("B3").NumberFormat = "General"
Sheets(Worksheets.Count).Range("B3").Value = CStr("01/" & ConvertMonth(month) & "/" & year)
'I also tried using
Sheets(Worksheets.Count).Range("B3").Value = Format("01/" & ConvertiMese(mese) & "/" & anno, "dd/mm/yyyy")
both ways are useless. It still convert the month into the day and so the result is 10/01/2024, where 10 are the days
where ConvertMonth is:
Select Case testoMese
Case "Gennaio"
ConvertiMese = "01"
Case "Febbraio"
ConvertiMese = "02"
Case "Marzo"
ConvertiMese = "03"
Case "Aprile"
ConvertiMese = "04"
Case "Maggio"
ConvertiMese = "05"
Case "Giugno"
ConvertiMese = "06"
Case "Luglio"
ConvertiMese = "07"
Case "Agosto"
ConvertiMese = "08"
Case "Settembre"
ConvertiMese = "09"
Case "Ottobre"
ConvertiMese = "10"
Case "Novembre"
ConvertiMese = "11"
Case "Dicembre"
ConvertiMese = "12"
End Select
If you have any suggestion or way to also improve the code, you are more than welcome :D
Thank you