Consulting

Results 1 to 5 of 5

Thread: Select entire row excep cells in merged area

  1. #1
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location

    Select entire row excep cells in merged area

    Suppose I have merged cells A1:C5
    How to select entire row 3 except Range(A3:C3)?

    Regards.
    Emily

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Emily
    Suppose I have merged cells A1:C5
    How to select entire row 3 except Range(A3:C3)?
    Bit weird, but it seems to work. Test like so

    ?notmerged(Range("3:3")).address


    Function NotMerged(testRange As Range) As Range
    Dim rngMA As Range
    Dim cell As Range
    Dim rngExclude As Range
    For Each cell In testRange
            Set rngMA = cell.MergeArea
            If rngMA.Address <> cell.Address Then
                If rngExclude Is Nothing Then
                    Set rngExclude = cell
                Else
                    Set rngExclude = Union(rngExclude, cell)
                End If
            End If
        Next cell
    If rngExclude Is Nothing Then
            Set NotMerged = testRange
        Else
            Set rngMA = rngExclude.Cells(1, 1).MergeArea
            rngMA.MergeCells = False
            Set NotMerged = AntiUnion(testRange, rngExclude)
            rngMA.MergeCells = True
        End If
    End Function
    
    
    Function AntiUnion(SetRange As Range, UsedRange As Range) As Range
    Dim saveSet
        saveSet = SetRange
        SetRange.ClearContents
        UsedRange = 0
        Set AntiUnion = SetRange.SpecialCells(xlCellTypeBlanks)
        SetRange = saveSet
    End Function

  3. #3
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    xld :

    Would you please elaborate on your function with code.

    Thanks
    Emily

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Emily
    Would you please elaborate on your function with code.
    I thought I had.


    NotMerged(Range("3:3")).Select

  5. #5
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    It works

    Thanks

Posting Permissions

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