I am using the VBA DateSerial function to separate dates in a string, but Excel Ends Sub when year in string is '1000'. What am I doing wrong? -


i using vba dateserial function separate dates in string, , populate them on worksheet excel ends sub when year in string '1000'.

here example:

string data: 2012-01-012012-03-01 2013-01-012013-03-01 1000-01-011000-01-01  vba code: private sub worksheet_change(byval target range)     if not intersect(target, columns(1)) nothing         on error goto safe_exit         application.enableevents = false         dim rng range, str string, rw long         each rng in intersect(target, columns(1))             str = rng.value             if len(str) >= 8                 sheet2                     rw = .cells(rows.count, 1).end(xlup).offset(1, 0).row                     .cells(rw, 1) = dateserial(left(str,4), mid(str, 6, 2), mid(str, 9, 2))                      .cells(rw, 2) = dateserial(mid(str, 11, 4), mid(str, 16, 2), mid(str, 19, 2))                  end           end if         next rng     end if safe_exit:     application.enableevents = true end sub 

no matter how many strings paste first worksheet, dates appear on second sheet until date year 1000. doing wrong?

excel bases dates number of days since midnight 30 december 1899 , not except negative dates.

even though appears can enter dates prior jan 1, 1900, if notice left-aligned. indicates have been accepted string values , not date.

you modify code set string value instead. valid date string automatically converted date. .cells(rw, 1) = cstr(dateserial(left(str,4), mid(str, 6, 2), mid(str, 9, 2)))

note 1/1/1904 minimum if 1904 date option selected.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -