简体   繁体   中英

List and count values in an Excel Spreadsheet

I have an excel worksheet organized in the following manner

Columns H to AK (named "Roadshow City 1, Roadshow City 2, through to Roadshow City 30) containing the names of a particular city

I need to list the names of each city and count how many times they appear in the column range. Essentially, I would like the result to look like

New York  23
San Francisco  15
London  12
etc

At the moment, I have typed the name of each city on another tab (by eyeballing each column) and then used the following formula to count them - for example for New York

=COUNTIF('IR Firms Registered on FUNDEXA'!$H$4:$AK$114,A2).  A2 being the cell in which I have typed "New York" 

Is there way to dynamically update this list so that it automatically adds to the list if a new city appears and/or count each additional instance of when a city name appears in the column range.

Is it possible to do this with a formula or pivot table (rather than macro code). I have a very limited understanding of macro coding.

I am happy to take suggestion from experts on how to reorganize or restructure the data to make it easier to list and count.

A pivot table won't work in this scenario, but a formula will.

You can use the following array formula. The formula references the cell above, so you need to adjust it to the column that you enter it in. If the formula is in cell A2 then it is

=IFERROR(INDEX($H$1:$AK$1,MATCH(0,COUNTIF(A$1:A1,$H$1:$AK$1),0)),"")

You need to confirm it with Ctrl - Shift - Enter and then copy it down as many rows as you think you will have cities in the columns.

The formula cannot be in row 1. Adjust the A$1:A1 to the column you are using and set the row number to one row above the formula row. Note the $ sign. It's important.

Then you can use in the next column (in my example cell B2)

=IF(A2="","",COUNTIF($H$1:$AK$1,A2))

and copy down.

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