LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Merging Multiple Named Ranges

If I wanted to also capture the value of the cells in the column to
the right of the ranges from the various sheets - how could that be
done? I would want to display this value to the right of the summary
range that is generated by the Display sub.

David

On Nov 19, 10:01*pm, wrote:
Thank you that works amazingly - now I just have to figure out how it
works.

On Nov 19, 5:02*pm, James Ravenswood
wrote:



On Nov 19, 6:29*pm, wrote:


On Nov 19, 3:18*pm, James Ravenswood
wrote:


On Nov 19, 4:14*pm, wrote:


I am trying to figure out a method to merge about 10 named ranges.. The
ranges vary in length but are all one column wide. The ranges are in
different worksheets but all within the same workbook. I am using
Excel 2007.


I know that there are duplicates within all the ranges but I only want
to retain one instance of the duplicate values and any of the unique
values from each range. How can this be done? I would prefer to
automate it with vb since I have 20 groups of these named ranges.


David


Hi David:


Sorry but could you explain the array method? can you still use the
union method with an array?


Merging ranges usually means using Union() to combine them into a
single range. *This does not work across worksheets. *That is why this
code fails:


Sub marine()
Dim r1 As Range, r2 As Range, r As Range
Set r1 = Sheets("Sheet1").Range("A1:A2")
Set r2 = Sheets("Sheet2").Range("B5:B6")
Set r = Union(r1, r2)
End Sub


The best you can do is to create an array containing the non-
duplicated contents of the ranges.- Hide quoted text -


- Show quoted text -- Hide quoted text -
call the Displayer
- Show quoted text -


Here is an example. *We have three different ranges on three different
sheets. *We call the Builder macro three times. *The Builder macro
accumulates a Collection of all the items in the sheets. *Finally we
call the Displayer macro. *The Displayer macro just dumps the items
back into one of the sheets in single collumn:


Dim coll As Collection


Sub main()
Set coll = New Collection
Dim r As Range
Set r = Sheets("Sheet1").Range("A1:A10")
Call Builder(r)
Set r = Sheets("Sheet2").Range("B1:B10")
Call Builder(r)
Set r = Sheets("Sheet3").Range("C1:C10")
Call Builder(r)
Set r = Sheets("Sheet1").Range("B1")
Call Displayer(r)
Set coll = Nothing
End Sub


Sub Builder(r As Range)
Dim arr
arr = r
On Error Resume Next
* For i = 1 To UBound(arr)
* * coll.Add arr(i, 1), CStr(arr(i, 1))
* Next i
End Sub


Sub Displayer(r As Range)
MsgBox coll.Count
For i = 1 To coll.Count
* * r.Value = coll.Item(i)
* * Set r = r.Offset(1, 0)
Next
End Sub- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting multiple named ranges Ted M H[_2_] Excel Programming 1 July 11th 09 07:58 PM
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... christian_spaceman Excel Programming 3 December 24th 07 01:15 PM
Multiple Named Ranges in the Same Column David Excel Worksheet Functions 2 May 9th 07 12:48 AM
merging multiple named ranges for validation list joes Excel Programming 1 January 7th 06 05:10 PM
how to avoid merging when pasting multiple ranges Stian Excel Programming 6 May 20th 05 03:29 PM


All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"