filter - MS-Excel copy specific cells in new worksheet after filtreing data -
i have worksheet "recalculated fs" columns : a, b, c, d, e ..ai want filter worksheet if ai = "yes" copy columns b , d in new worksheet "sheet2", have code copy columns , don't know how work column b , d, ps : want rename header of "sheet2" , b -- > columnb , c--> columnc
sub tgr() dim wsdata worksheet dim wsdest worksheet set wsdata = sheets("recalculated fs") set wsdest = sheets("sheet2") wsdata.range("ai2", wsdata.cells(rows.count, "ai").end(xlup)) .autofilter 1, "yes" .currentregion.copy wsdest.range("a1") .autofilter end end sub
help please ? need add filter 1 (ai column), filter 2 (column ak) , how can in code :
option explicit sub tgr() dim wsdata worksheet dim wsdest worksheet set wsdata = sheets("recalculated fs") set wsdest = sheets("sheet2") ' set wsdata sheet active, allow filterring wsdata.select wsdata.range("ai2", wsdata.cells(rows.count, "ai").end(xlup)) ' column ai col num 35 .autofilter 35, "yes" end wsdata.columns("b:b").select selection.copy wsdest.select columns("b:b").select activesheet.paste wsdata.select wsdata.columns("d:d").select selection.copy wsdest.select columns("d:d").select activesheet.paste wsdest.range("b1").value = "columnb" wsdest.range("d1").value = "columnd" end sub
the code below copies column b , column d worksheet sheet2, when column ai = yes.
edit 1: copies column b , column d 1 one sheet 2 (without copying column c)
edit 2: added second filter criteria of column ak = yes
option explicit sub tgr() dim wsdata worksheet dim wsdest worksheet set wsdata = sheets("recalculated fs") set wsdest = sheets("sheet2") ' set wsdata sheet active, allow filterring wsdata.select wsdata.range("ai2", wsdata.cells(rows.count, "ai").end(xlup)) ' column ai col num 35 .autofilter 35, "yes" .autofilter 37, "yes" end wsdata.columns("b:b").select selection.copy wsdest.select columns("b:b").select activesheet.paste wsdata.select wsdata.columns("d:d").select selection.copy wsdest.select columns("d:d").select activesheet.paste wsdest.range("b1").value = "columnb" wsdest.range("d1").value = "columnd" end sub
Comments
Post a Comment