Excel VBA timestamp and username -


the code below detects data when inputted column , automatically inserts current user cell right. code add timestamp well. need log user name , time. suggestions?

private sub worksheet_change(byval target excel.range)     dim rcell range     dim rchange range      on error goto errhandler     set rchange = intersect(target, range("a:a"))     if not rchange nothing         application.enableevents = false         each rcell in rchange             if rcell > ""                 rcell.offset(0, 1)                     .value = username()                  end              else                 rcell.offset(0, 1).clear             end if         next     end if  exithandler:     set rcell = nothing     set rchange = nothing     application.enableevents = true     exit sub errhandler:     msgbox err.description     resume exithandler end sub  public function username()     username = environ$("username") end function 

you use date & " " & time. output date , time concatenated so:

17/07/2013 11:49:39 pm 

here code date/time value added next column:

private sub worksheet_change(byval target excel.range) dim rcell range dim rchange range  on error goto errhandler set rchange = intersect(target, range("a:a")) if not rchange nothing     application.enableevents = false     each rcell in rchange         if rcell > ""             rcell.offset(0, 1).value = username()                rcell.offset(0, 2).value = date() & " " & time()   <-- added line                   else             rcell.offset(0, 1).clear         end if     next end if 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -