Book1 | ||||
---|---|---|---|---|
A | B | |||
1 | Due on 01/04/2009-Opening balance adj | 01/04/2009 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1 | =DATEVALUE(MID(A1,FIND("/",A1)-2,10)) |
A | B | |
---|---|---|
Due on 01/04/2009-Opening balance adj |
Book1 | ||||
---|---|---|---|---|
A | B | |||
1 | Due on 01/04/2009-Opening balance adj | 01/04/2009 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1 | =DateFromString(A1) |
Public Function DateFromString(inputString As String) As Date
DateFromString = CDate(Mid(inputString, InStr(1, inputString, "/") - 2, 10))
End Function
A | B | |
---|---|---|
Due on 01/04/2009-Opening balance adj |
Public Function DateFromString(inputString As String) As Date
DateFromString = CDate(Mid(inputString, InStr(1, inputString, "/") - 2, 10))
End Function
I have different strings in different cells.Some of these strings containing date and some are not.I have to check if a string contains any date then is the date value is lesser than a specific date.[Please Write the solution using VBA]What would be ideal is if you could state *all* your requirements rather than adding additional comments and suggestions as we go. What do you want to achieve?
WBD
Public Function GetDateFromString(inputString As String) As Date
Dim regEx As Object
Dim dateParts() As String
Set regEx = CreateObject("VBScript.RegExp")
GetDateFromString = 0
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = "\d{1,2}\/\d{1,2}\/\d{4}"
If .Test(inputString) Then
dateParts = Split(.Execute(inputString).Item(0).Value, "/")
GetDateFromString = DateSerial(CLng(dateParts(2)), CLng(dateParts(1)), CLng(dateParts(0)))
End If
End With
End Function