简体   繁体   中英

Excel formula: How to refer a cell by its column name

How can I change my excel formula if I need to replace direct reference to the cell by the column name of this cell? For example, instead of

SUM(A1:B1)

I want to use something like

SUM({Column1}:{Column2})

I know about structured reference, but I can not convert my excel dataset into named table. Do I have any options?

This answer assumes that the column name is the content of the header row for that column.

Say we have data like:

在此处输入图像描述

and we want to sum part of the row based on certain months, say between Feb and Jun. In B6 enter Feb and in C6 enter Jun and in D6 enter:

=SUM(INDEX(A2:L2,MATCH(B6,A1:L1,0)):INDEX(A2:L2,MATCH(C6,A1:L1,0)))

在此处输入图像描述

So by changing B6 and C6 we can change the part of the second row we are summing.

EDIT#1:

  1. If we re-arrange the headers, the formula should adapt to the re-arrangement
  2. The formula I posted was plain-vanilla. It should work on old versions of Excel as well as the current version. I am using the US Locale. You may need to check the spelling of functions and may need to use a ; rather than a , as the field separator character.

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