Convert Date Problem

Michele317

New Member
Joined
Apr 29, 2024
Messages
20
Office Version
  1. 365
Platform
  1. 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:
  1. 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)
  2. 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)
  3. 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
  4. Above the code:
MsgBox CStr(month) & " " & CStr(ConvertMonth(month))
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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What does
VBA Code:
Sheets(Worksheets.Count).Range("B3").Value = CDate("01/" & ConvertMonth(month) & "/" & year)
Give you?
 
Upvote 1
Solution
What does
VBA Code:
Sheets(Worksheets.Count).Range("B3").Value = CDate("01/" & ConvertMonth(month) & "/" & year)
Give you?
Thank you! It works!!! I don't know how and why but it worked xD
What exactly did "CDate"?

Thank you again :)
 
Upvote 0
Happy it helped and welcome to the forum

From Microsoft
1714409406374.png
 
Upvote 1

Forum statistics

Threads
1,223,879
Messages
6,175,142
Members
452,615
Latest member
bogeys2birdies

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