VBA Excel date yyyy/mmm/dd to yyyy/mm/dd -
i'm writing small vba manage , convert date external tables , i'm stuck on strange date format like: yyyy/mm/dd need convert date a1 , paste b2
as tamplate use columns a1 , b1: a1= date converted b1= paste destinaton of converted dat
- a1
- 2012.jan.04
- 2012.nov.04
2012.dct.04
- b1
- 04.01.2012
- 04.11.2012
- 04.12.2012
what tested is:
- formula convert (with created dictionary) - cannot use in case of many dates convert
- vba date convert - cannot see date a1 proper date , nothing
- format date in excel build-in function "formating" - nothing
- also function "text-to-column" tested - still nothing
it looking i'm stuck on simple hard move forward why i'm asking help.
thanks ideas.
i use following formula in b1
:
=date(left(a1,4),match(mid(a1,6,3),{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dct"},0),right(a1,2))
what looks strange abbreviation "dct" december. maybe have change array literal {"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dct"}
according language.
using vba
following function
used:
function convert_yyyy_mmm_dd_text2date(stext string) variant dim iyear integer dim imonth integer dim smonth string dim iday integer dim amonths variant dim bfound boolean amonths = array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dct") on error goto errhandler iyear = cint(left(stext, 4)) smonth = mid(stext, 6, 3) iday = cint(right(stext, 2)) imonth = 0 ubound(amonths) if amonths(imonth) = smonth bfound = true exit end if next if bfound convert_yyyy_mmm_dd_text2date = dateserial(iyear, imonth + 1, iday) else goto errhandler end if on error goto 0 exit function errhandler: convert_yyyy_mmm_dd_text2date = "conversion not possible" end function
Comments
Post a Comment