VBA & Macro Problems

Create an Excel Named Range from Another Cell

John WilsonJohn Wilson Dec 2, 2026 868 views

Question details

The user wants to use text in a cell, such as a student's name, to create a named range in Excel.

How to Create an Excel Named Range from Another Cell
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains a label in one cell and data that the user wants to identify with that label as a defined name.
Observed behavior
A standard Excel formula cannot create or rename a defined name when the cell text changes.
Before you start

Identify the cell containing the proposed name and the cells the name should refer to. Excel names must follow naming rules: they cannot contain spaces, start with a number, or look like cell references.

Solution 1Recommended

Use VBA to Create a Named Range from a Cell Value

Use a macro when you need Excel to read a cell's text and create a workbook-level name.

This example reads the name from A1 and makes it refer to B2:B10 on the active worksheet. Running the macro creates the name; it does not automatically rename it if A1 changes later.

1
Prepare the name and range

Enter a valid, unused Excel name in A1 and place the data in B2:B10. Change these references in the macro if your worksheet uses different cells.

2
Open the VBA editor

In desktop Excel, open Developer > Visual Basic, then choose Insert > Module.

3
Add and run the macro

Paste the following code into the module, return to the worksheet, and run CreateNameFromCell from Developer > Macros: Sub CreateNameFromCell() Dim ws As Worksheet Dim nm As String Dim ref As String Set ws = ActiveSheet nm = Trim$(CStr(ws.Range("A1").Value)) ref = "='" & Replace(ws.Name, "'", "''") & "'!$B$2:$B$10" ws.Parent.Names.Add Name:=nm, RefersTo:=ref End Sub

4
Check the result

Open Formulas > Name Manager and confirm that the new name refers to the intended range. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you want to keep the macro.

Use VBA to Create a Named Range from a Cell Value
Check the name first: An invalid name can cause the macro to fail, and an existing name can be replaced. Check Name Manager before running it.
Create named ranges in WPS

Create a Named Range in WPS Spreadsheet

Use WPS Spreadsheet to create a named range using a valid name copied from a worksheet cell. The name is created manually and does not automatically change when the cell value changes.

  1. 1. Open the workbook: Open your spreadsheet in WPS Spreadsheet and locate the cell containing the proposed name.
  2. 2. Copy a valid name: Copy the cell text and ensure it follows spreadsheet naming rules, with no spaces and no leading number.
  3. 3. Select the data: Select the cells you want the name to refer to, then choose Formulas > Define Name.
  4. 4. Define the range: Paste the name into the name field, check the range reference, and confirm to create the named range.
Create and manage named ranges for worksheet dataOpen and edit Microsoft Excel XLSX filesWork in a familiar spreadsheet interfaceUse WPS Office for free
microsoft office alternative - wps office

Frequently Asked Questions

Can an Excel formula create a defined name from a cell?

No. A formula can return or look up data, but it cannot create or rename a defined name. Use VBA or Formulas > Create from Selection instead.

Will a named range change when I edit its source label?

No. Editing the label does not automatically rename the defined name. Use Formulas > Name Manager to edit it, or run a suitably designed macro.

Why can't I use a student's full name as an Excel range name?

Defined names cannot contain spaces and must follow other naming rules. Use a valid name such as John_Doe, and check it in Formulas > Name Manager.

Do I need a separate named range for each student?

Not necessarily. If student names and grades are in corresponding columns, use a formula such as =XLOOKUP(D2,A2:A10,B2:B10) to return the grade for the name in D2.