I'm trying to do simple tasks with date type but what I'm getting is not what I want. I would like to Split some cell value with delimiter and return string values to DateValue method.
My code
Dim str2() As String
str2() = Split(Cells(ActiveCell.Row, 7).Value, ".")
Dim date1 As Date
date1 = DateValue(str(0) & "-" + str(1) & "-" & str(2))
What I'm trying to do is getting some specific date format. Date in the cell is formated like this : 26.05.14 (day.month.year) and I want to have format like this 2014-05-26(year-month-day). That's all. DateValue method returs me a date 2000-01-02. I don't knwo how can I look into the str2() array to see what values are there after Split method. How can I do that ?
It seems VBA is completely different from VB.NET ... I'm not experienced with VBA. Thanks
Cells(ActiveCell.Row, 7).Valuereturning? Can you try:date1 = CDate(Replace(Cells(ActiveCell.Row, 7).Value, ".", "/"))Cells(ActiveCell.Row, 7).Value? When I point a mouse abovestr2()it doesn't prompt me anything after executing Split method. On the other hand when I try to see its values like this :Dim strCheck1 As String strCheck1 = str2(0)it gives me an compile error "Subscript out of range"date1 = CDate(Replace(Cells(ActiveCell.Row, 7).Value, ".", "/"))gives me "Type mismatch" error.MsgBox Cells(activecell.row, 7).Valueas the first line in yourSuband tell us what the value isMsgBox Cells(activecell.row, 7)returned me an empty value. When I triedMsgBox Cells(activecell.row, 6)which was not empty it returned me 26.05.14 value