# Named Ranges

#### bailey537

##### Board Regular
Hi

Is there a way to define a named range from a selection of cells that begin with a particular letter e.g. X from A1:A1000?

Cheers

### Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You could perhaps go through the cells, finding each one that began with X and combine them using union in VB, but it could wind up being too complex a definition. What is is you're trying to achieve?

I have a list of codes and i want to basicly determine how many begin with X quickly. As it is a big list I don't want to loop through them all. I also need to know their locations within the list

Wouldn't filtering the list achieve this? You could use a countif if you just wanted a count

=COUNTIF(A:A,"X*")

or if you really want to create the range:

Code:
``````Sub ComplexRange()
Dim complexRng As Range, rng As Range, rStr As String
Set rng = Columns(1).Find(what:="X*", lookat:=xlWhole)
If Not rng Is Nothing Then
Do
If complexRng Is Nothing Then
Set complexRng = rng
Else
Set complexRng = Union(complexRng, rng)
End If
Set rng = Columns(1).FindNext(rng)
End If
complexRng.Select
End Sub``````

actually, change

Code:
`` complexRng.select``
to
Code:
``complexRng.Name = "myComplexRange"``
If you want to actually name the range

cheers for your help. I went with your first idea about the filtering and then naming the range with the visible cells. Do you know how to find the length of the range once this is generated?

you could try counting the cells using .cells.count

Code:
``msgbox range("myComplexRange").cells.count``
or maybe
Code:
``msgbox range("myComplexRange").rows.count``

Replies
7
Views
358
Replies
5
Views
260
Replies
3
Views
318
Replies
10
Views
550
Replies
2
Views
346

1,211,685
Messages
6,103,294
Members
447,853
Latest member
olddutch7

### 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.

### Which adblocker are you using?

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

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