I am trying the following UDF
Code: Select all
Sub Test()
Debug.Print Date
Debug.Print ToHijri(Date)
End Sub
Function ToHijri(DateString As String) As String
Dim c As VbCalendar, d As Date
c = Calendar
Calendar = vbCalGreg
d = DateString
Calendar = vbCalHijri
ToHijri = d - 1
Calendar = c
End Function
If I typed the date 20/9/2021 in a cell and format cells > Date > and from Calendar type selected "Hijri", I got the correct date which is 13/02/1443
While this UDF returns the correct Hijri date
Code: Select all
Function DHijri(dtGegDate As Date) As String
VBA.Calendar = vbCalHijri
DHijri = dtGegDate
VBA.Calendar = vbCalGreg
End Function
Any ideas?