excel vba - Run-time error message 91 (object variable not set) -
i have following code in excel vba (using excel 2010), find specific date, in european format (dd/mm/yyyy), , cancel rows below cell (with date in it):
sub macro1() ' macro1 dim variant ' input box insert date = inputbox("insert date of last entry format dd/mm/yyyy", "user date", format(now(), "dd/mm/yyyy")) if isdate(a) = format(cdate(a), "dd/mm/yyyy") else msgbox "date in wrong format!" end if 'find date above, in variable a, in excel sheet cells.find(what:=a, after:=activecell, lookin:=xlformulas, _ lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _ matchcase:=false, searchformat:=false).activate range(selection, selection.end(xldown)).select range(selection, selection.end(xltoright)).select selection.entirerow.delete end sub
however, when run macro, run-time error message 91
object variable not set.
many help.
this error appears because find
method didn't return result, yet try activate not existing range in same line.
option explicit sub macro1() dim variant dim foundrng range ' ' macro1 ' ' input box insert date = inputbox("insert date of last entry format dd/mm/yyyy", "user date", format(now(), "dd/mm/yyyy")) if isdate(a) = format(cdate(a), "dd/mm/yyyy") else msgbox "date in wrong format!" end if 'find date above, in variable a, in excel sheet set foundrng = cells.find(what:=a, after:=activecell, lookin:=xlformulas, _ lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _ matchcase:=false, searchformat:=false) if foundrng nothing = false foundrng.activate range(selection, selection.end(xldown)).select range(selection, selection.end(xltoright)).select selection.entirerow.delete else msgbox "entered date not found!" end if end sub
Comments
Post a Comment