Consulting

Results 1 to 11 of 11

Thread: Deselect or Remove from Range?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Deselect or Remove from Range?

    Is ther any way to deselect a Range or rememove
    a range from another range (without removing the
    underlying data, just the range definition).

    I tried the following code:

    'Does a set difference on two ranges.
     'For example:
     '   subtractRanges = subtractee - subtractor
    'Returns the range of cells that are IN the
     'subtractee and NOT in the subtractor.
    'Example 2:
     'RangeA = "A1:A20"
     'RangeB = "A1:A10"
     'RangeC = subtractRanges(RangeA, RangeB)
    'RangeC contains "A11:A20"
     
    Function subractRanges(subtractee As Range, subtractor As Range) As Range
    Dim c As Range
    For Each c In subtractee
        If Intersect(c, subtractor) Is Nothing Then
            If subractRanges Is Nothing Then
                Set subractRanges = c
            Else
                Set subractRanges = Union(subractRanges, c)
            End If
        End If
     Next c
     End Function
    However the opteration I want to do is this:
    Dim garbage As Range
     Set garbage = SubtractRanges.subractRanges(ActiveSheet.Cells, Range(ActiveSheet.PageSetup.PrintArea))
    If you do this, the subroutine runs for A LONG TIME as it is trying
    to compare every cell in the entire sheet to the print area.

    Suggestions?
    Last edited by Aussiebear; 04-29-2023 at 08:46 PM. Reason: Adjusted the code tags

Posting Permissions

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