BUY EXCEL BOOKS ONLINE: 1. VBA & Macros      2. VBA for Modelers      3. Excel 2013 VBA and Macros     
4. Excel VBA for Dummies      5. Excel with VBA & .NET      6. Mastering VBA      7. Excel 2013 Programming

Invert the Selection


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
                    Set rNew = Union(rNew, cell)
                End If
            End If
        Next cell
    End If
    If Not rNew Is Nothing Then
    End If
End Sub

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