+ Reply to Thread
Results 1 to 3 of 3

Combining Named Ranges

Hybrid View

dmartindale Combining Named Ranges 08-10-2007, 03:47 PM
Ron Coderre Combining Named Ranges 08-10-2007, 04:19 PM
dmartindale it helps 08-10-2007, 05:50 PM
  1. #1
    Registered User
    Join Date
    08-10-2007
    Posts
    8

    Combining Named Ranges

    Hi everyone,

    I'm looking for a way to take 2 named ranges in a worksheet (that may have space between them) and create a third rectangular named range whose boundaries are the outer-boundaries of the initial 2 ranges. Union will not work because the third range must include any blank space between the initial 2 ranges.

    Thanks!

    Dave

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Combining Named Ranges

    See if this gives you some ideas:

    Sub GatherRanges(rRng1 As Range, rRng2 As Range)
       Dim MinCol, MaxCol, MinRow, MaxRow
       Dim rComboRange As Range
       
       With WorksheetFunction
             MinRow = .Min(rRng1.Row, rRng2.Row)
             MinCol = .Min(rRng1.Column, rRng2.Column)
       
             MaxRow = .Max(rRng1.Row + rRng1.Rows.Count, rRng2.Row + rRng2.Rows.Count) - 1
             MaxCol = .Max(rRng1.Column + rRng1.Columns.Count, rRng2.Column + rRng2.Columns.Count) - 1
       End With
       
       Set rComboRange = Range(Cells(MinRow, MinCol), Cells(MaxRow, MaxCol))
       rComboRange.Select
       MsgBox rComboRange.Address
    End Sub
    
    Sub Test()
       GatherRanges rRng1:=Range("C3:F5"), rRng2:=Range("H4:L6")
    End Sub
    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    08-10-2007
    Posts
    8

    it helps

    Thanks, that was perfect!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1