excel - Pass date input string to cell range -
i trying pass date entered in input box through range of cells in specific column. range isn't specific must fill cells contain data in column.
'date input box sub dateinput() dim datestring string, thedate date datestring = application.inputbox("enter certificate date") if isdate(datestring) thedate = datevalue(datestring) else msgbox "that's not good!" end if end sub
this far i've gotten, can't seem feed entered date range of cells.
you can use following sample replace non empty cells in range date:
sub dateinput() dim datestring string, thedate date dim rng range dim lastrow long dim lastcol long dim ws worksheet dim wb workbook set wb = activeworkbook '<-- workbook working in set ws = wb.activesheet '<-- worksheet working in ws if application.worksheetfunction.counta(.cells) <> 0 '<-- finding last row used lastrow = .cells.find(what:="*", _ after:=.range("a1"), _ lookat:=xlpart, _ lookin:=xlformulas, _ searchorder:=xlbyrows, _ searchdirection:=xlprevious, _ matchcase:=false).row '<-- finding last column used lastcol = .cells.find(what:="*", _ after:=.range("a1"), _ lookat:=xlpart, _ lookin:=xlformulas, _ searchorder:=xlbycolumns, _ searchdirection:=xlprevious, _ matchcase:=false).column else lastcol = 1 '<-- selecting first column if nothing found lastrow = 1 '<-- selecting first row if nothing found end if end set rng = activesheet.range(cells(1, 1), cells(lastrow, lastcol)) '<-- can set range here datestring = application.inputbox("enter certificate date") if isdate(datestring) thedate = datevalue(datestring) each c in rng.cells if c.value <> "" c.value = thedate end if next else msgbox "that's not good!" end if end sub
Comments
Post a Comment