vba - Excel macro to find text value in sheet, copy the respective column, and paste whole column on another sheet -


i have set excel file paste data workbook sheet 1, , sheet 2 set show values using

a1 =if(not(isblank(sheet1!b1)),sheet1!b2,"")  

throughout whole sheet (with cell references changing according needs).

normally work me fine, problem when download new raw data , copy sheet 1, columns in sheet 1 have moved on me due addition of random new columns , formula sheet 2 breaks set reference respective column sheet 1 have selected, rather actual data need.

below example:

sheet 1 (day 1) (simply copying raw data workbook)

  |     |   b   |   c   |   d   |   e   |   f   | --+-------+-------+-------+-------+-------+-------+ 1 | cat 1 | cat 2 | cat 3 | cat 4 | cat 5 | cat 6 | 2 |   1a  |   1b  |   1c  |   1d  |   1e  |   1f  | 3 |   2a  |   2b  |   2c  |   2d  |   2e  |   2f  | 4 |   3a  |   3b  |   3c  |   3d  |   3e  |   3f  | 

sheet 2 (day 1) (desired output using noted formula)

  |     |   b   |   c   | --+-------+-------+-------+ 1 | cat 2 | cat 6 | cat 4 | 2 |   1b  |   1f  |   1d  | 3 |   2b  |   2f  |   2d  | 4 |   3b  |   3f  |   3d  | 

sheet 1 (day 2) (copying raw data next day or so)

  |     |   b   |   c   |   d   |   e   |   f   |   g   | --+-------+-------+-------+-------+-------+-------+-------+ 1 | cat 1 |random | cat 2 | cat 2 | cat 4 | cat 5 | cat 6 | 2 |   1a  |   1x  |   1b  |   1c  |   1d  |   1e  |   1f  | 3 |   2a  |   2x  |   2b  |   2c  |   2d  |   2e  |   1f  | 4 |   3a  |   3x  |   3b  |   3c  |   3d  |   3e  |   1f  | 

sheet 2 (day 2) (resulting output due new unwanted column)

  |     |   b   |   c   | --+-------+-------+-------+ 1 |random | cat 5 | cat 3 | 2 |   1x  |   1e  |   1c  | 3 |   2x  |   2e  |   2c  | 4 |   3x  |   3e  |   3c  | 

due fact dealing on 100 columns of data , 20 thousand rows, impractical me either search changed columns in sheet 1 or modify formulas every time new data in sheet 2.

so question is, suggest way write macro in excel search text value in row 1 of sheet 1, copy entire column containing value, , pasting entire column in sheet 2? confident in use of formulas in excel have no knowledge on macros , appreciate help.

 can try using macro:  sub macro1() ' ' macro1 macro '      dim cell range     = 1 50         sheets("sheet1").select         if cells(1, i).value = "cat 2"         columns(i).select         selection.copy         sheets("sheet2").select         range("a1").select         activesheet.paste         end if         if cells(1, i).value = "cat 6"         columns(i).select         selection.copy         sheets("sheet2").select         range("b1").select         activesheet.paste         end if         if cells(1, i).value = "cat 4"         columns(i).select         selection.copy         sheets("sheet2").select         range("c1").select         activesheet.paste         end if     next end sub  

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -