excel - Type Mismatch error -
i have below code giving me run time error 13, type mismatch on line "if ws1.cells(i,13)="yes" then" column (column m) contains either blank cells, or "yes". i've tried redefining "i" string, , didn't change anything. goal every row "yes" in column m, entire row copied on second sheet named "output". error appreciated, open other ideas may suit goal. thanks!
sub sadface() dim ws1 worksheet: set ws1 = thisworkbook.sheets("trades") dim ws2 worksheet: set ws2 = thisworkbook.sheets("output") = 2 ws1.range("m65536").end(xlup).row if ws1.cells(i, 13) = "yes" ws1.rows(i).copy ws2.rows(ws2.cells(ws2.rows.count, 2).end(xlup).row + 1) end if next end sub
it sounds if have manually removed errors external data. if bringing data workbook operation repeated on regular basis, may wish automate it.
sub happyface() dim long dim ws1 worksheet: set ws1 = thisworkbook.sheets("trades") dim ws2 worksheet: set ws2 = thisworkbook.sheets("output") ws1.columns(13) on error resume next .specialcells(xlcelltypeconstants, xlerrors).clearcontents .specialcells(xlcelltypeformulas, xlerrors).clearcontents err.clear on error goto 0 end ws1 = 2 .cells(rows.count, "m").end(xlup).row if .cells(i, 13) = "yes" .rows(i).copy ws2.rows(ws2.cells(ws2.rows.count, 2).end(xlup).row + 1) end if next end end sub
as try avoid use of on error resume next¹, expedient method of dealing range.specialcells method when not sure whether exist or not.
¹the concept of breaking see if exists has seemed plain wrong me.
Comments
Post a Comment