How to use names of columns instead of references?

excelos

Well-known Member
Joined
Sep 25, 2011
Messages
591
Office Version
  1. 365
Platform
  1. Windows
Hello

I have a sheet with the first row being the titles of the columns.

I want to use COUNTIFS but I don't want to use the references of the columns as these may change.

I want to use instead the names of the columns.

I use INDEX/MATCH to locate the name of the column I need.

How can I use that information in COUNTIFS so that I specify the column $A:$A to contain the criteria I need?

Thanks!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Something along the lines of


Excel 2013/2016
ABCDEFGHI
1LongitudeEastingNorthingGridRefCountyDistrictCounty
2-2.655301354569173596ST545735SomersetNorth SomersetNorfolk3
3-1.344331443249437642SE432376West YorkshireLeeds
4-1.275226450212197760SU502977OxfordshireVale of White Horse
5-1.289136449258196951SU492969OxfordshireVale of White Horse
6-3.190212323218524128NY232241CumbriaAllerdale
71.54832640180310380TG401103NorfolkBroadland
8-2.113507392835566041NY928660NorthumberlandNorthumberland
9-1.290897448764235209SP487352OxfordshireCherwell
10-1.871541408530449548SE085495West YorkshireBradford
11-2.606423359983413693SD599136LancashireChorley
12-2.605033360065412521SD600125LancashireChorley
13-2.135258391089381329SJ910813CheshireCheshire East
14-1.610059425448494294SE254942North YorkshireHambleton
15-0.900953472628425079SE726250East Riding of YorkshireEast Riding of Yorkshire
161.135007614834248873TM148488SuffolkMid Suffolk
17-2.277924381289304406SJ812044ShropshireShropshire
181.313923625314288111TM253881NorfolkSouth Norfolk
190.094746544198225189TL441251HertfordshireEast Hertfordshire
201.265345619946333551TG199335NorfolkNorth Norfolk
Sheet1
Cell Formulas
RangeFormula
I2=COUNTIF(INDEX(A2:F20,0,MATCH(H1,A1:F1,0)),H2)
 
Upvote 0
select all columns with data, from menu > Formulas > Create from selection > pick top row
 
Last edited:
Upvote 0
What does the INDEX(A2:F20,0,MATCH(H1,A1:F1,0)) return?

It searches for the whole table A2:F20 in row zero. I don't get that bit. Is it the row of the A2?
Then it finds the County in the row with the titles which is 5.

So which the return of the INDEX is the cell column 0 and row 5.

How does that specify the column E:E?
 
Upvote 0
It returns the entire column (row 2 to row 20) where County is found in row 1
 
Last edited:
Upvote 0
Also, the problem is that I need to know the bottom right cell of the table.
I do not always know that.
Is there a work around?
 
Upvote 0
To phrase it in other words:

I want to countif the cells, that a different column has a specific value.

I need to specify this column by the name of its title in the first row.

I want this column to be unlimited length, i.e. $A:$A (with A to be the column with the specific column title mentioned in the first row)

If it cannot be unlimited length, I want the length to extend to the either the lowest cell with data in the whole sheet or to the lowest cell with data in a specific column.

Any ideas?
 
Upvote 0
To get the entire column just use
=COUNTIF(INDEX(A:F,0,MATCH(H1,A1:F1,0)),H2)
 
Last edited:
Upvote 0
To get the entire column just use
=COUNTIF(INDEX(A:F,0,MATCH(H1,A1:F1,0)),H2)

Thanks but I do not know the F, I do not know if I will cover the whole table with A:F or I will need A:G, or A:H etc.

I will know the F,G,H if I do an index/match for the title of the column I want, but how do I do feed that info into the A:F bit?
 
Upvote 0
It would help if you gave some exact information, so far you have given us nothing to work with.
I am not willing to keep guessing at what you are trying to do.
Please explain what you are trying to do, where your data is, where your criteria are etc, etc.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top