copying range of cells and pasting to the first empty row more effective code? Excel -


i have macro takes selection of cells "new search" , paste range first open cell in "past searches" i'm thinking code ineffective. have ideas of how can improve this?

sub macro5() range("a3:j3").select range(selection, selection.end(xldown)).select selection.copy sheets("past searches").select range("a1").end(xldown).offset(1, 0).select activesheet.paste worksheets("new searches").activate application.cutcopymode = false end sub 

first, don't have use .select or .activate on cells/worksheets you'll manipulate, reference them directly. can slow down code.

the .copy method can take destination parameter, don't have use .paste somewhere else.

also, .end property isn't reliable. it's better use usedrange instead.

you can pretty in 1 line.

worksheets("new search").range("a3:j3").copy destination:=worksheets("past searches").usedrange.columns(1).offset(1, 0) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -