简体   繁体   中英

Converting cells in a column in one worksheet as column headers in another worksheet

Example:

Worksheet 1

 id category 
  1    dog
  2    cat 
  ....

Worksheet 2

name ,  dog , cat ....

However the first worksheet will grow so I can't use a paste special and when I link the cells =worksheet1!B2 and when I drag the fill handle downwards it gives the result I want. How would I achieve this because when I drag the fill handle sideways it doesn't give the desired affect

Thanks

In my screenshot I've kept everything on one page so it is easier to see everything in one spot. 在此处输入图片说明

The code used is: =INDEX($B:$B,COLUMNS($E$1:E1)+1) or =INDEX($B:$B,COLUMNS($D$1:E1))

  1. First the system is indexing column B.
  2. Next we have a "counter" built that tells it to return the value in the "nth" column. In the first formula (and the one in the screenshot) I have a +1 so it doesn't return the word "category"; as an alternative, in the second example, I just move the starting absolute reference one cell to the left.
  3. Finally, after placing this in the desired cell (with appropriate cell references), simply drag to the right.

If you have any questions about this method or its implemntation, please feel free to ask.

Sample File: HERE

You can write the formula as below:

=INDIRECT("worksheet1!B"&COLUMN(B1))

And then drag it to the right.

Indirect is usually something to avoid. In your example, if you move a cell or change the name of the first worksheet it will not work anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM