I am trying to extract a date from a text string and write it to another column is a spreadsheet.
The date is in the input string in col A and I want to extract this date and write it to col F in the format dd/mm/yy.
In the code below, at the line Cells(c, "f").Value = str1, str1 shows the date in the format I want it - for the date in line 1, str1 is 29/3/22
and for line 2, str1 shows as 2/12/22 but 12/02/22 is written to col F.
Can someone tell me why the incorrect dates are written to col F for lines 2, 3 and 5 and how I can get the dates I want?
Thanks.
The date is in the input string in col A and I want to extract this date and write it to col F in the format dd/mm/yy.
In the code below, at the line Cells(c, "f").Value = str1, str1 shows the date in the format I want it - for the date in line 1, str1 is 29/3/22
and for line 2, str1 shows as 2/12/22 but 12/02/22 is written to col F.
Can someone tell me why the incorrect dates are written to col F for lines 2, 3 and 5 and how I can get the dates I want?
Thanks.
VBA Code:
Sub driver()
srow = 1
lrow = Sheets("input").Cells(Sheets("input").Rows.Count, "A").End(xlUp).Row
c = 1
For i = srow To lrow
inputString = Cells(i, "a").Value
arrsplitstring = Split(inputString)
k = UBound(arrsplitstring)
p1 = 0
temp = arrsplitstring(j)
ii = Len(temp)
For jj = ii To 1 Step -1
If Mid(temp, jj, 1) = "." Then
p1 = jj
Exit For
End If
Next jj
str1 = Mid(temp, 1, p1 - 1)
Cells(c, "f").Value = str1
c = c + 1
Next i
End Sub