excel - Find cells on one sheet and copy the rows to another sheet -
i have sheet called backlog containing rows , columns of data. need code search row row in 2nd last column looking #n/a. when finds #n/a needs check last column if contains c or not. if contains c whole row should appended sheet called logoff. if last column not contain c whole row should appended sheet called denied. row should deleted original backlog sheet once moved either logoff or denied. code have below not working. after first statement goes end sub, there not compiling errors.
private sub commandbutton2_click() dim imbacklogsh worksheet set imbacklogsh = thisworkbook.worksheets("backlog") dim logoffsh worksheet set logoffsh = thisworkbook.worksheets("claims logged off") dim deniedsh worksheet set deniedsh = thisworkbook.worksheets("claims denied") imbacklogsh.select dim long = 3 cells(rows.count, 13).end(xlup).row if cells(i, 13).value = "#n/a" if cells(i, 14).value = "c" imbacklogsh.rows(i).entirerow.copy destination:=logoffsh.range("a" & logoffsh.cells(rows.count, "a").end(xlup).row + 1) else imbacklogsh.rows(i).entirerow.copy destination:=deniedsh.range("a" & deniedsh.cells(rows.count, "a").end(xlup).row + 1) end if end if next end sub
try if cells(i, 13).text = "#n/a" then
. #n/a
error code, not value; however, range.text property can examined or iserror function used examine cell's contents error.
if cells(i, 13).text = "#n/a" 'alternate iserror 'if iserror(cells(i, 13)) if cells(i, 14).value = "c" imbacklogsh.rows(i).entirerow.copy _ destination:=logoffsh.range("a" & logoffsh.cells(rows.count, "a").end(xlup).row + 1) else imbacklogsh.rows(i).entirerow.copy _ destination:=deniedsh.range("a" & deniedsh.cells(rows.count, "a").end(xlup).row + 1) end if end if
however, individual cell examination not necessary , time consuming. autofilter method can used isolate #n/a
c
, #n/a
<>c
.
private sub commandbutton2_click() dim imbacklogsh worksheet, logoffsh worksheet, deniedsh worksheet set imbacklogsh = thisworkbook.worksheets("backlog") set logoffsh = thisworkbook.worksheets("claims logged off") set deniedsh = thisworkbook.worksheets("claims denied") imbacklogsh if .autofiltermode .autofiltermode = false .cells(1, 1).currentregion .autofilter field:=13, criteria1:="#n/a" .autofilter field:=14, criteria1:="c" .resize(.rows.count - 1, columns.count).offset(1, 0) if cbool(application.subtotal(103, .cells)) .copy destination:= _ logoffsh.cells(rows.count, "a").end(xlup).offset(1, 0) 'optionally delete originals .entirerow.delete end if end .autofilter field:=14, criteria1:="<>c" .resize(.rows.count - 1, columns.count).offset(1, 0) if cbool(application.subtotal(103, .cells)) .copy destination:= _ deniedsh.cells(rows.count, "a").end(xlup).offset(1, 0) 'optionally delete originals .entirerow.delete end if end end if .autofiltermode .autofiltermode = false end end sub
Comments
Post a Comment