Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Selecting multiple named ranges | Excel Programming | |||
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... | Excel Programming | |||
Multiple Named Ranges in the Same Column | Excel Worksheet Functions | |||
merging multiple named ranges for validation list | Excel Programming | |||
how to avoid merging when pasting multiple ranges | Excel Programming |