Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: How to refer to entire column in a formula by column title?

Tags:

excel

I want to write a formula like =SUM(tab2!A:A) but instead use the column title of A which is say "count". How can I modify this to look more like: =SUM(tab2!"count")?

The reason I want to do this is because I copy and paste a spreadsheet from another source in tab2 and the column referring to "count" may be in a different column. I want the formula to give me the correct calculation as soon as I paste the new spreadsheet by automatically finding the column to sum up by title name.

I must be missing something because this seems like a very basic question and I can't find the answer anywhere...

Thanks for your help!

like image 917
ru111 Avatar asked Nov 22 '25 08:11

ru111


1 Answers

I like the idea of naming ranges proposed by @Doug, but if the issue is that you are dumping your data in [and you don't know in advance which column is going to be where] and would need to rename your range every time, there are other options - I suggest using OFFSET. OFFSET allows you to dynamically create a range, starting at a particular point and moving down/up / right/left for as many rows and columns as you determine.

In your case, you will need to combine that with a method for searching the columns to see which one says "Count". I am assuming that your column headings are always in row 1. If they aren't [or if they aren't always in row 2, or any row you know in advance]... you can get around that but then I'd recommend you try to make your data more uniform instead of creating unnecessary Excel workarounds.

In total your formula would look like this:

=SUM(OFFSET(A1,,MATCH("Count",1:1,0)-1,ROWS(A:A),1))

What this does is first determine which column the word "Count" is found in, in row 1. Then it subtracts 1 from that number - this now equals the number of columns to the right that it is, from column A. It uses offset to create a reference to that column, for all rows, and sums those rows together.

like image 125
Grade 'Eh' Bacon Avatar answered Nov 24 '25 20:11

Grade 'Eh' Bacon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!