Friday 15 June 2012

Excel (VBA): data formatted as date not recognized -



Excel (VBA): data formatted as date not recognized -

so have excel file, vba code in it. problematic bit need sort lot of info barcode number first, date of visit (each barcode visits multiple times).

this works fine random test info generated. gets sorted barcode, date latest earliest.great!

but not, when seek utilize actual data, doesn't: barcode gets sorted right not date. actual info come android app (xscan) has csv files output.

unfortunately, info exports looks "21/10/2014". when seek have sorted, sorts according first number, not date (not useful)... no matter month is, if day 31 st, it'll place highest.

i have tried following: changing datatype & forth, , run code datatype set different things, still doesn't work.

****how can create excel understand 21/10/2014 read date, though comes csv file , looks string/weird division?****

ideally, solution coded vba somehow... i'm dealing low-tech skills users....

edit: see screenshot below: column need sort column h. doesn't matter if set info type number, date, general.... still same. code:

function sorting_all(mysheet worksheet, myrangerow range, myrangecol range, secondsort string) dim mycol range set mycol = getcol(mysheet, secondsort) mysheet.range("a1", mysheet.cells(myrangerow.row, myrangecol.column)).sort key1:=mysheet.range("a1"), order1:=xlascending, key2:=mysheet.range(columns(mycol.column).address()), order2:=xldescending, header:=xlyes, orientation:=xlsortcolumns end function

the barcode in column , be, hence hardcode (i know know). that's key1. key2 date of visit (though function called sort other things, hence secondsort variabel).

further edit: apparently output file application isn't saved .csv (even though that's app claims), saved excel 97-2003 file. if copy-past file, doesn't work. if saved file csv (properly), copy-past it.... works. not gonna lie, hate excel. not built-in function alter app. heart of matter might between excel 97-2003 file format & excel 2010 file use... in case seem importing info through vba best answer.

in similar cases, problem imported date not match settings in windows command panel regional settings. excel interprets dates not fit settings text, , converts other dates incorrectly.

several fixes can used.

alter output info source date formats match -- not feasible. change windows regional short date settings match csv format -- not thought "lo-tech users" import file rather opening it. whether manually or via vba, have chance utilize text import wizard, allow specify imported date format.

excel vba date data-type-conversion

No comments:

Post a Comment