Format of dates

0

This is a simple prototype of the function that I need because the problem arises with the Date object that takes the Weekday method as a parameter, as you can see, my function receives the values that you enter referenced by cells and in data type String. The drawback is that if I write for example "dd / mm / yyyy" does not recognize it, it should enter as "mm / dd / yyyy" but I need to see in the cells of my table in the first format. Can I use the string "dd / mm / yyyy" in some way and turn it into "mm / dd / yyyy" with some date method or something? Or if or should I resort to partitioning of strings and conversion to integers to create a date object with 3 numeric parameters?

Thank you in advance

Function cantObligaciones(docente As String, fecha As String, art As Integer)
If art = 80 Then
Dim datos As Range
Set datos = Worksheets(2).Range("h5:o10")
col = Application.WorksheetFunction.Weekday(fecha, vbMonday)
cantObligaciones = Application.WorksheetFunction.VLookup(docente, datos, col, 1)
End If

End Function

THANKS

    
asked by Sofia E Torres 25.10.2018 в 23:59
source

2 answers

0

Cut the date and exchange the month with the day to generate a date with the format expected by the Weekday function:

col = Application.WorksheetFunction.Weekday(Mid(fecha, 4, 2) + "/" + Left(fecha, 2) + "/" + Right(fecha, 4), vbMonday)
    
answered by 26.10.2018 в 09:37
0

Try converting the date you have saved in text to a data type date before. For this, use Cdate

  

CDate function with VBA

col = Application.WorksheetFunction.Weekday(CDate(fecha), vbMonday)

    
answered by 28.10.2018 в 20:47