January 13th, 2013, 2:25 pm
Following Tula's suggestion:Function dateRegex(dat As Date, timlen As String) As Date' Function that takes a date in a date format +' a time length in string format and returns a' date in a VBA date format' Create regexDim reg As RegExp' Create the regex object for the yearSet reg = New RegExpWith reg .IgnoreCase = True ' Case insensitive, just in case ... .Global = True ' Several occurrence to be found .Pattern = "\d+" ' Find out the year, month and day into the stringEnd WithDim mat As ObjectSet mat = reg.Execute(timlen)' Create variables to store date calculation resultsDim res1 As Date, res2 As Date, res3 As Dateres1 = DateAdd("yyyy", mat(0), dat)res2 = DateAdd("m", mat(1), res1)res3 = DateAdd("d", mat(2), res2)' Return the desired value to the sheetdateRegex = res3 End Function That works well here. Please, tell me if it is okay for you.
Last edited by
tags on January 12th, 2013, 11:00 pm, edited 1 time in total.