Excel VBA runtime error '13' type mismatch -
sub comparelines() application.screenupdating = false activesheet.cells(3, 3).activate while activecell.value <> "" if activecell.value - activecell.offset(-1, 0).value < 0 activecell.entirerow.delete else activecell.offset(1, 0).activate end if wend application.screenupdating = true end sub this code i'm error on.
the error excel vba runtime error "13 type mismatch.
the line error on: if activecell.value - activecell.offset(-1, 0).value < 0 then
this code had worked on previous worksheets, when import macro onto new worksheet, doesn't seem work. solution have found on don't seem apply circumstance, on problem appreciated.
in general, on error resume next should extremely careful with.
if put in code, start ignoring errors , if works code after not happy @ (or think amateur or job-defender). having said that, cpearson has article it, that's worthy read - http://www.cpearson.com/excel/errorhandling.htm
last not least, make sure change on error resume next else, once realize why errors happening.
in case, idea use isnumeric function, avoid typemismatch error. if other errors appear, try avoid them similar matter.
dim v1 range, v2 range while activecell.value <> "" set v1 = activecell.value set v2 = activecell.offset(-1) if isnumeric(v1) , isnumeric(v2) 'both numeric, it's safe perform arithmetic against these values if v1 - v2 < 0 activecell.entirerow.delete else activecell.offset(1, 0).activate end if else: activecell.offset(1, 0).activate end if wend 
Comments
Post a Comment