+ Reply to Thread
Results 1 to 12 of 12

How to invert cell selection in excel? I cant find how to do it...

  1. #1
    Registered User
    Join Date
    02-06-2013
    Location
    Mexico
    MS-Off Ver
    MS Office 2016
    Posts
    99

    How to invert cell selection in excel? I cant find how to do it...

    Experts,

    I tried many codes from the internet to invert Cells selection at excel, but they doesnt work.

    Anyone has a code that can be shared with me? I just want to select a cell or cells, execute the macro and invert selection of them.

    thanks!

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: How to invert cell selection in excel? I cant find how to do it...

    Select a range (up and down) and try this.
    Please Login or Register  to view this content.
    Long winded but it should do until someone comes with a shorter code (Not faster I think!!!!)

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: How to invert cell selection in excel? I cant find how to do it...

    Assuming you have a specific range of cells you want to invert (and not the entire worksheet), this should work. This code only scans the range C4:H15, so expand your range as needed. It checks to see if each cell in that range is selected, and if not, creates a list of those cells, then finally selects those addresses.
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: How to invert cell selection in excel? I cant find how to do it...

    A second possibility.
    Again, if I understand your request right.
    Select a vertical range and run this.
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: How to invert cell selection in excel? I cant find how to do it...

    And my last suggestion.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-06-2013
    Location
    Mexico
    MS-Off Ver
    MS Office 2016
    Posts
    99

    Re: How to invert cell selection in excel? I cant find how to do it...

    Thanks all for respond Thread but they didnt work

    Thew swap the values between selection, but doesn't select the oposite cells.

    I mean, if i Select A1:A5 and B3:B7. When i run the macro, i want to select rest of the workbook cells. this means, All from A6 to AXXXX and B1:B2 and B8 to XX:XX

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: How to invert cell selection in excel? I cant find how to do it...

    What is the purpose of this? What are you trying to achieve?
    Selecting is very seldom needed so there should be an alternative
    Last edited by jolivanes; 08-30-2021 at 06:51 PM.

  8. #8
    Registered User
    Join Date
    02-06-2013
    Location
    Mexico
    MS-Off Ver
    MS Office 2016
    Posts
    99

    Re: How to invert cell selection in excel? I cant find how to do it...

    Quote Originally Posted by jolivanes View Post
    What is the purpose of this? What are you trying to achieve?
    Selecting is very seldom needed so there should be an alternative
    Good question. I requiere it for two different scopes:

    1. First. Select All Locked Cells , excluding Un-Locked ones. This means, the oposite of this code:

    Please Login or Register  to view this content.
    2. Second. Swap cells selection, this means, if i have A,B,C cells selected. When i execute the macro this three will be un-select and the rest of the cells sheets should be selected.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: How to invert cell selection in excel? I cant find how to do it...

    What if you change the "False" to "True" here?
    Please Login or Register  to view this content.
    and change all the "unlockedCells" to "lockedCells".
    Also make sure when you protect your sheet that you can select both locked and unlocked cells.

  10. #10
    Registered User
    Join Date
    02-06-2013
    Location
    Mexico
    MS-Off Ver
    MS Office 2016
    Posts
    99

    Re: How to invert cell selection in excel? I cant find how to do it...

    Quote Originally Posted by jolivanes View Post
    What if you change the "False" to "True" here?
    Please Login or Register  to view this content.
    and change all the "unlockedCells" to "lockedCells".
    Also make sure when you protect your sheet that you can select both locked and unlocked cells.
    That was my first test, it doesnt work.

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: How to invert cell selection in excel? I cant find how to do it...

    I ran this on a temporary test book and it works as you want (I think).
    Please Login or Register  to view this content.
    For locked cells, copy this same macro but change "True" to "False" and in the message change "Unlocked" to "Locked".

    But there still is the question of why select cells. What are yoy going to do with the selected cells?
    Last edited by jolivanes; 08-31-2021 at 05:56 PM.

  12. #12
    Registered User
    Join Date
    02-06-2013
    Location
    Mexico
    MS-Off Ver
    MS Office 2016
    Posts
    99

    Re: How to invert cell selection in excel? I cant find how to do it...

    Quote Originally Posted by jolivanes View Post
    I ran this on a temporary test book and it works as you want (I think).
    Please Login or Register  to view this content.
    For locked cells, copy this same macro but change "True" to "False" and in the message change "Unlocked" to "Locked".

    But there still is the question of why select cells. What are yoy going to do with the selected cells?
    Thanks for the code, it works for other porpoise. But not for what i need, let me answer your question, that probably can clarify what i want to do.

    But there still is the question of why select cells. What are yoy going to do with the selected cells?

    I need to invert selection from Locked to Unlocked cells and Viceversa when the workbook its not Protected (Locked). This because i programmed a sub routine to right click in order to identify witch cells are locked and witch cells are not. That's why i need to Select a range, then when macro executes. Locked or Unlocked cells needs to be selected, depending on the option clicked.

    This will execute different sub routines based on if they're locked - selected or unlocked selected.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Invert Cell Value (No=Y and Yes=N)
    By nathanexcelhelp in forum Excel General
    Replies: 2
    Last Post: 01-04-2017, 08:45 AM
  2. How to invert text in a cell
    By rollymilitar in forum Excel General
    Replies: 11
    Last Post: 03-16-2014, 10:14 PM
  3. [SOLVED] Help to find a function of invert growth
    By sacha99 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-13-2013, 02:20 AM
  4. Invert Excel selection
    By aaajeto in forum Excel General
    Replies: 1
    Last Post: 10-09-2013, 09:14 AM
  5. Invert Selection of Cells
    By jman0707 in forum Excel General
    Replies: 6
    Last Post: 10-10-2008, 04:54 PM
  6. [SOLVED] How do I invert a column in Excel?
    By 3-togo in forum Excel General
    Replies: 1
    Last Post: 02-08-2006, 11:35 AM
  7. [SOLVED] Invert Excel Selection
    By Significent in forum Excel General
    Replies: 0
    Last Post: 03-11-2005, 10:06 PM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1