year n+1 < year n in excel vba -


i have problem excel not recognizing years properly.

here code

' sort value max = sheets("booking").cells(rows.count, "a").end(xlup).row range("a1:h" & max).select activeworkbook.worksheets("booking").sort.sortfields.clear activeworkbook.worksheets("booking").sort.sortfields.add key:=range("d2:d" & max) _ , sorton:=xlsortonvalues, order:=xldescending, dataoption:=xlsortnormal activeworkbook.worksheets("booking").sort.sortfields.add key:=range("a2:a" & max) _ , sorton:=xlsortonvalues, order:=xlascending, dataoption:=xlsortnormal activeworkbook.worksheets("booking").sort     .setrange range("a1:h" & max)     .header = xlyes     .matchcase = false     .orientation = xltoptobottom     .sortmethod = xlpinyin     .apply end  ' mark past booking in italic , in red if not validated l = 2 max     if format(cdate(booking.cells(l, 5).value), "dd-mm-yy") < format(cdate(cells(1,10).value), "dd-mm-yy")         booking.cells(l, 5).entirerow.font.italic = true             if booking.cells(l, 5).offset(0, 3).value = ""                 booking.cells(l, 5).entirerow.font.color = vbred             else                 booking.cells(l, 5).entirerow.font.color = vbblack             end if     end if next l 

the column d full of date formated dd-mm-yy
cell (1,10) = now()

when code needs sort orders date : np, puts 2014 orders in front of 2013 orders

but

when code applies italic format dates < now, 2014 orders considered past , code put them in italic

what doing wrong ?

it clear in loop comparing dates strings, not surprised different results. should change

if format(cdate(booking.cells(l, 5).value), "dd-mm-yy") < format(cdate(cells(1,10).value), "dd-mm-yy") 

to

if booking.cells(l, 5).value < booking.cells(1,10) 

on unrelated note, value of variable cells in second part of if statement? did forget precede booking.?


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -