Results 1 to 4 of 4

Thread: How to invert a selection in Microsoft Excel

  1. #1
    Join Date
    Oct 2011
    Posts
    89

    How to invert a selection in Microsoft Excel

    I have some groups of cells scattered at different parts of the sheet (saying what the cell next to it is) selected. How do I invert my selection so that instead of the "title" cells being selected the "data" cells are. There is no "invert selection" in the edit menu like there is for other programs.

  2. #2
    Join Date
    Nov 2010
    Posts
    503

    Re: How to invert a selection in Microsoft Excel

    I am assuming that you want to move to the right side rather than to the left:
    Code:
    Sub movsel()
    Set r1 = Selection
    Set rf = Nothing
    For Each r In r1
    If rf Is Nothing Then
    Set rf = r.Offset(0, 1)
    Else
    Set rf = Union(rf, r.Offset(0, 1))
    End If
    Next
    rf.Select
    End Sub
    If you wanted to move to the left use Offset(0,-1) instead.

  3. #3
    Join Date
    Nov 2010
    Posts
    422

    Re: How to invert a selection in Microsoft Excel

    Maybe I was a little to vague. Here is the problem, I have a sheet with 16 cells, 4 by 4, and I have 6 cells selected using the control key. They are randomly scattered over the 16. I want to invert so that the 6 cells that were selected are not now selected and the 10 that were not, are selected. They are not always next to each other. There is no menu that I can find that will swap my selection. Is there a hidden menu or combination of keys to do this.

  4. #4
    Join Date
    Jul 2011
    Posts
    434

    Re: How to invert a selection in Microsoft Excel

    This macro does what you want:
    Code:
    Sub jon()
    Set r1 = Selection
    Set r2 = Range("A14")
    Set rinv = Nothing
    For Each r In r2
    If Intersect(r, r1) Is Nothing Then
    If rinv Is Nothing Then
    Set rinv = r
    Else
    Set rinv = Union(rinv, r)
    End If
    End If
    Next
    If rinv Is Nothing Then
    Else
    rinv.Select
    End If
    End Sub
    It works on the range from A1 through D4. Change this to suit your needs. Macros are very easy to install and use:
    1. CNTRL-F11 brings up the VBE window
    2. ALT-I / ALT-M opens a fresh module
    3. paste the stuff in and close the VBE window

    If you save the workbook, the macro will be saved with it. To remove the macro:
    1. bring up the VBE window as above
    2. clear the code out
    3. close the VBE window

Similar Threads

  1. Replies: 2
    Last Post: 21-02-2012, 07:48 PM
  2. Replies: 2
    Last Post: 21-02-2012, 01:01 PM
  3. Replies: 4
    Last Post: 13-02-2011, 10:37 AM
  4. Cannot Group that Selection error in Excel 2000
    By marcman in forum Windows Software
    Replies: 3
    Last Post: 01-12-2009, 11:41 AM
  5. Print a selection of cells in MS Excel (row / column)?
    By mikey32 in forum Windows Software
    Replies: 3
    Last Post: 10-03-2009, 07:28 PM

Tags for this Thread

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
  •  
Page generated in 1,714,027,324.61909 seconds with 16 queries