excel vba - Copy range of cells after IF and paste to column "J".....Not entire row. VBA -


i have following code in vba:

    if sheets("sheet1").cells(i, "c").value = "dog" , sheets("sheet1").cells(i, "d").value = "toy" sheets("sheet1").cells(i, "a").copy destination:=sheets("toys").range("a" & rows.count).end(xlup).offset(1) end if     if sheets("sheet1").cells(i, "c").value = "cat" , sheets("sheet1").cells(i, "d").value = "toy" sheets("sheet1").cells(i, "a").copy destination:=sheets("toys").range("j" & rows.count).end(xlup).offset(1) end if 

instead of selecting column "a" know if there simple way of selecting columns "a h".

thank time.

you can change sheets("sheet1").cells(i, "a").copy to:

sheets("sheet1").range(sheets("sheet1").cells(i, "a"),sheets("sheet1").cells(i, "h")).copy 

to reduce number of times need include worksheet reference, can use with ... end with:

with sheets("sheet1")     .range(.cells(i, "a"),.cells(i, "h")).copy end 

note there full stop before each cells method.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -