excel vba copy multiple column based on column header listed in cell ranges -


i want copy multiple columns sheet1 sheet2 based on column header (eg. date, name, id, amount,etc), column header listed in sheet3, a1:a10.eg. date, name, id, amount,etc.

after googling few hours, got below code, work copying 1 single column, how can copy multiple column? part of code need change? appreciate time , help.

thank you.

sub copyspecifccolumn()      set mr = range("a1:e1")      each cell in mr          if cell.value = "date" cell.entirecolumn.copy      next  end sub 

untested:

sub copycols()      dim h range, f range, sht1, rngdest range      set sht1 = thisworkbook.sheets("sheet1")     set rngdest = thisworkbook.sheets("sheet2").range("a1") 'start pasting here      'loop through headers copy     each h in thisworkbook.sheets("sheet3").range("a1:a10").cells         'find header on sheet1         set f = sht1.rows(1).find(h.value, , xlvalues, xlwhole)         if not f nothing             'found header: copy column             f.entirecolumn.copy rngdest             set rngdest = rngdest.offset(0, 1) ' move destination         end if         set f = nothing     next h  end sub 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -