Problems using DATEDIF() function

MacroShark

New Member
Joined
Jun 5, 2018
Messages
6
In my sheet I import dates in the format dd-mmm-yyyy which is the english region format. My problem is that my Windows is set up to Danish region format (dd-mmm-åååå). This causes the DATEDIF() function to fail. The DATEDIF() function works if I go to the Windows region settings and change to English, but I would like to avoid this as it is tedious and it needs to be set back every time after use.

My question is, can I use VBA to help me out with changing the region setting temporarily while the workbook is open and then set back when closing it? Or any other suggestions on how to solve this issue would be highly appreciated.

Thank you
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
I did not find a way to change this setting but what if you tried to reformat the date within the function.

Code:
Sub Test()


Dim myDate1 As Date
Dim myDate2 As Date
Dim myVal As Long


myDate1 = Application.WorksheetFunction.Text(Range("G9").Value, "mm-dd-yyyy")
myDate2 = Application.WorksheetFunction.Text(Range("H9").Value, "mm-dd-yyyy")


myVal = DateDiff("m", myDate1, myDate2)


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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