excel vba - VBA runtime error 13 Type Mismatch If statment -
i receive runtime error '13': type mismatch when try run code. debug highlights 'if' statements, can't figure out mistake is. appreciated.
dim integer dim lastrow long workbooks("template part_ii.xlsx").worksheets(2).activate lastrow = cells(rows.count, 1).end(xlup).row = 2 lastrow if cells(i, 1).value <> "#n/a" , cells(i, 1).value <> "00000000-000" cells(i, 1).copy worksheets(1).range("a2:a" & lastrow).pastespecial xlpastevalues end if next
and in fact i'm trying this:
have 1 sheet have 100 rows of various ids , want copy ids sheet without possible non id strings in case can #n/a or 00000000-0000, don't want non copied cells appear blanks in destination range.
wrap accesses cell inside check ensures cell contains no error value (e.g. cell 'containing' division 0)
... = 2 lastrow if not iserror(cells(i, 1).value) if cells(i, 1).value <> "#n/a" , cells(i, 1).value <> "00000000-000" cells(i, 1).copy worksheets(1).range("a2:a" & lastrow).pastespecial xlpastevalues end if end if next ...
note: tried insert condition @ front of existing if
seems vba not use short-circuiting therefore wrapping
update due comment
you may want change code
dim integer dim lastrow long dim targetrow long workbooks("template part_ii.xlsx").worksheets(2).activate lastrow = cells(rows.count, 1).end(xlup).row targetrow = 2 = 2 lastrow if not iserror(cells(i, 1).value) if cells(i, 1).value <> "#n/a" , cells(i, 1).value <> "00000000-000" cells(i, 1).copy worksheets(1).cells(targetrow, 1).pastespecial xlpastevalues targetrow = targetrow + 1 end if end if next
Comments
Post a Comment