Tuesday 15 September 2015

excel - VBA creating date with strings -



excel - VBA creating date with strings -

i'm trying simple tasks date type i'm getting not want. split cell value delimiter , homecoming string values datevalue method.

my code

dim str2() string str2() = split(cells(activecell.row, 7).value, ".") dim date1 date date1 = datevalue(str(0) & "-" + str(1) & "-" & str(2))

what i'm trying getting specific date format. date in cell formated : 26.05.14 (day.month.year) , want have format 2014-05-26(year-month-day). that's all. datevalue method returs me date 2000-01-02. don't knwo how can str2() array see values there after split method. how can ?

it seems vba different vb.net ... i'm not experienced vba. thanks

you storing homecoming of split "str2" using variable "str" datevalue input, not defined in code (so it's empty). avoid kind of mistakes putting "option explicit" on top of project, in vba not compulsory vb.net but, indeed, optional. here code working:

dim str2() string str2 = split(range("a2").value, ".") dim date1 date date1 = datevalue(str2(0) & "-" + str2(1) & "-" & str2(2))

excel vba date

No comments:

Post a Comment