excel - VBA - Only Check for Date inside a DD/MM/YYYY - HH/MM/SS value -


i've checked through multiple topics unfortunately couldn't find solution need.

i have cells needs include date , time in following custom format: dd/mm/yyyy hh:mm

and have check cells see if matches. if does, notifies me approaching due time.

dim mylimit         double  mylimit = date  set formularange = range("e5:e35")     each formulacell in formularange.cells     formulacell             if .value = mylimit                 *do action* 

this works if set date value such 02/05/2016 in cells, default midnight , triggers action. although 02/05/2016 2:45 pm doesn't work.

so need check first part of cell date value , trigger action if fits today's date.

i tried few solutions such as:

dim mylimit         double  mylimit = cdate(format(date, "dd-mmm-yyyy"))  set formularange = range("e5:e35")     each formulacell in formularange.cells     formulacell             if .value = mylimit                 *do action* 

and

dim mylimit         date  mylimit = format((now), "dd/mm/yyyy")  set formularange = range("e5:e35")     each formulacell in formularange.cells     formulacell             if .value = mylimit                 *do action* 

but doesn't work. doesn't detect should action date = today.

anyone can enlighten me on this?

actual script:

option explicit  public function autorun() application.ontime + timevalue("00:01:00"), "tasktracker2" end function  public sub tasktracker2() dim formulacell          range dim formularange    range dim notsentmsg      string dim mymsg           string dim sentmsg         string dim sendto          string dim ccto            string dim bccto           string dim mylimit         double dim mylimit2        double   notsentmsg = "not sent" sentmsg = "sent" sendto = range("d2") ccto = range("e2") bccto = range("f2")  mylimit = date mylimit2 = ((round(now * 1440, 0) - 30) / 1440)  set formularange = range("e5:e35") on error goto endmacro: each formulacell in formularange.cells     formulacell             if datevalue(.value) = mylimit                 mymsg = sentmsg                 if .offset(0, 1).value = notsentmsg                     strto = sendto                     strcc = ccto                     strbcc = bccto                     strsub = "[task manager] reminder need to: " & cells(formulacell.row, "a").value                     strbody = "hello sir, " & vbnewline & vbnewline & _                         "this email notify task : " & cells(formulacell.row, "a").value & " following note: " & cells(formulacell.row, "b").value & " nearing due date." & vbnewline & "it wise complete task before expires!" & _                         vbnewline & vbnewline & "truly yours," & vbnewline & "task manager"                     if sendmail(strto, strsub, strbody, strcc) = true mymsg = sentmsg                  end if             else                 mymsg = notsentmsg             end if              if .value = mylimit2                 mymsg = notsentmsg             end if          application.enableevents = false         .offset(0, 1).value = mymsg         application.enableevents = true      end  next formulacell autorun   exitmacro: exit sub  endmacro: application.enableevents = true  msgbox "some error occurred." _      & vblf & err.number _      & vblf & err.description  end sub 

so need check first part of cell date value

use datevalue function, e.g.:

 if datevalue(.value) = mylimit      ' *do action* 

nb: date type consists of date and time parts.

the datevalue function returns date part of date type. there timevalue function returns time part date type.

some revisions mismatch error, tested value 2/5/2016 14:45:

dim mylimit date  mylimit = date  set formularange = range("e5:e35") each formulacell in formularange.cells     formulacell             if datevalue(.value) = mylimit                 ' something... 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -