Create named ranges from Column and Row headers

BillXL

New Member
Joined
Oct 6, 2008
Messages
29
Is there any way in Excel to create single-cell named ranges from a combination of the labels in the rows and column of a spreadsheet.

Here is an example:
CompanyACompanyBCompanyCCompanyD
Sales100200
Cost300
Profit

<tbody>
</tbody>

I would like the first cell (containing the 100) to have a defined name of (something like) “SalesCompanyA”, and the second cell to be “SalesCompanyB”. And so on – e.g. the cell with 300 in it should be “CostCompanyA”.

I can do it manually, but I have a huge spreadsheet & was hoping it could be automated. Just to be clear, it needs to be a single cell range. I know you can create a range from a selection – but this seems to create ranges of the entire row and/or column.

Many thanks

Bill
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I assumed the data is in B2 to a various row and column.
Code:
Sub NameCells()
Col = Cells(1, Columns.Count).End(xlToLeft).Column
Row = Cells(Rows.Count, 1).End(xlUp).Row
For Each Cell In Range(Cells(2, 2), Cells(Row, Col))
    ActiveWorkbook.Names.Add Cells(Cell.Row, 1).Value & Cells(1, Cell.Column).Value, Cell.Address
Next
End Sub

Plz,Try it on a sample data first!

ZAX
 
Upvote 0
ZAX

That is brilliant - thank you so much. It does exactly what I need.

Thanks again,

Bill
 
Upvote 0
Hi,

Another alternative here rather than creating named ranges for every cell in the table is to create names based on the row and column headers (highlight the range and create from selection using top row and left column), and then use the intersection operator (space). Then you can use a formula like:

=Sales CompanyA

to return 100.

For more on the intersection operator and a short video showing exactly how to do this see:
How to write 2 Way Lookup Formulas in Excel? | Chandoo.org - Learn Microsoft Excel Online
 
Upvote 0
Hi circledchicken

I'm amazed! I have never seen that functionality before. Very useful - thank you.

Regards

Bill
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

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