why does it create a named range?

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
Because of the number of cells I had to incorporate in a named range I broke same into four then to run it I use this:
Code:
Sub search()
Application.Union([searchone], [searchtwo], [searchthree], [searchfour]).Name = "searchall"
Dim i As Long
Dim rngCell As Range
i = 1
For Each rngCell In [searchall]
  rngCell.Value = Range("toplistall")(i)
  i = i + 1
Next
End Sub

Before I run the code I look at my named ranges and there is no "searchall"
After I run the code a new named range is created named "searchall"

When I look at it it has bits and pieces of the four named ranges in it but not a complete list of those cells.
The code works great but still I am curious.
Can anyone explain it?
As far as I can tell nothing in the code suggest the creation of this new named range (that's the way I read it anyway)
Many thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Than you, can you explain then why the code works since the list of cells in it is incomplete?
or is it not necessary to the end result? and if it is how can I abort the creation of it?
 
Upvote 0
If you don't want to create a name use a range object variable, eg:

Code:
Sub search()
    Dim searchall As Range
    Dim i As Long
    Dim rngCell As Range
    Set searchall = Application.Union([searchone], [searchtwo], [searchthree], [searchfour])
    i = 1
    For Each rngCell In searchall.Cells
        rngCell.Value = Range("toplistall")(i)
        i = i + 1
    Next
End Sub

Sorry I don't know what you mean by "the list of cells in it is incomplete".
 
Upvote 0
I think I've got it now.
I can get rid of the first four named ranges and just keeps the one titled:'searchall"
I see now that it is a complete representation of what's in the four after all.
 
Upvote 0
sorry was typing and did not notice your response.
this is what I meant by "the list of cells in it is incomplete".
When I first tried to put on one named range 131 cells I could not.
I decided to break them down in 4 "sub" named ranges and to make it work I use the code shown above.

I just noticed that indeed "searchall" indeed covers all the cells and not just few.
I will decide after running the code the first time to either delete the four and keep "searchall" or follow your advise and edit the code thus avoiding the creation of "searchall" in the first place.

Many thanks for your time
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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