Invert the Selection



Code:

Sub InvertSelection()
    Dim rBig As Range
    Dim rSmall As Range
    Dim cell As Range
    Dim rNew As Range
    Set rBig = ActiveSheet.UsedRange
    If TypeName(Selection) = "Range" Then
        Set rBig = Selection.Parent.UsedRange
        Set rSmall = Selection
    End If
    If Not rSmall Is Nothing Then
        For Each cell In rBig.Cells
            If Intersect(cell, rSmall) Is Nothing Then
                If rNew Is Nothing Then
                    Set rNew = cell
                Else
                    Set rNew = Union(rNew, cell)
                End If
            End If
        Next cell
    End If
    If Not rNew Is Nothing Then
        rNew.Select
    End If
End Sub



Comments

Anonymous said…
This comment has been removed by a blog administrator.