Named Ranges

bailey537

Board Regular
Joined
Jun 30, 2008
Messages
65
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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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?
 
Upvote 0
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
 
Upvote 0
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
        rStr = rng.Address
        Do
            If complexRng Is Nothing Then
                Set complexRng = rng
            Else
                Set complexRng = Union(complexRng, rng)
            End If
            Set rng = Columns(1).FindNext(rng)
        Loop While rng.Address <> rStr
    End If
    complexRng.Select
End Sub
 
Upvote 0
actually, change

Code:
 complexRng.select
to
Code:
complexRng.Name = "myComplexRange"
If you want to actually name the range
 
Upvote 0
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?
 
Upvote 0
you could try counting the cells using .cells.count

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

Forum statistics

Threads
1,214,581
Messages
6,120,372
Members
448,957
Latest member
BatCoder

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