excel - VBA - copy rows - if it found error, then continue in copy cells -
i have macro copy cells below's cells.
sub copyrows2() dim lastrow long worksheets("ready upload") ' <-- here should sheet's name lastrow = .cells(.rows.count, "ad").end(xlup).row ' last row in column c = 2 lastrow if range("ad" & i) > "" , range("ad" & + 1) = "" range("ad" & i).copy range("ad" & + 1).pastespecial xlpastevalues application.cutcopymode = false else end if next end activewindow.scrollrow = 1 'scrolling screen top end sub
it works fine, until found #n/a
, give me error msg: run-time error '13' - type mismatch. in case, skip , continue in copy rows.
[
could advise me, how that, please?
many thanks!
option 1
the easiest way embed on error resume next
in code. work.
option 2 if want 1 step more professional, can use this:
sub copyrows2() dim lastrow long on error resume next 'your code if err.number = 13 err.clear on error goto 0 end sub
it disregard error 13
, tell if there other errors, quite useful.
option 3 check error this:
if not iserror(range("ad" & i)) , not iserror(range("ad" & + 1)) 'embed code here end if
Comments
Post a Comment