+ Reply to Thread
Results 1 to 7 of 7

How to unselect a row within a range?

  1. #1
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    How to unselect a row within a range?

    I allow the user to select a bunch of cells, and then perform operations on the rows of those cells. However there is a certain row that I want to unselect automatically if it is selected.

    I have a custom shortcut menu that appears when the user right clicks on the selected rows: when the user right-clicks, and one of the cells selected is in the "forbidden row" - then I want cells in the forbidden row to be unselected. How do I do this?

    I have looked online to find out how to unselect a range, but it only shows how to unselect the entire selected range, and not just a subset of the selected range.

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    10-30-2019
    Location
    Bistrita, Romania
    MS-Off Ver
    2019; 365
    Posts
    231

    Re: How to unselect a row within a range?

    How do you "allow" the user to select a bunch of cells?

    I'm assuming in Format Cells - Protection tab you have "Locked" unchecked. And then you password protect the sheet.
    If so, then when you password protect the sheet you could uncheck "Select locked cells" - this will prevent selecting the "forbidden row" altogether, without the need to "unselect".
    To show your appreciation
    Click ★ Add reputation!

  3. #3
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: How to unselect a row within a range?

    Thanks but is there another way without using the lock cells? User can select a bunch of cells by holding down Cntrl key and selecting a bunch of cells.

  4. #4
    Forum Contributor
    Join Date
    10-30-2019
    Location
    Bistrita, Romania
    MS-Off Ver
    2019; 365
    Posts
    231

    Re: How to unselect a row within a range?

    Put the next code in the Sheet code to prevent users from selecting any cell in row 4:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,438

    Re: How to unselect a row within a range?

    In the example the named range, IGNORE_CELLS, can not be selected

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,420

    Re: How to unselect a row within a range?

    Here is a ThisWorkbook_SheetSelectionChange event procedure (so it works on any sheet in the workbook) posted by snb here...

    http://dailydoseofexcel.com/archives...e-of-the-same/

    that lets you hold down the CTRL key while "selecting" a cell or range to deselect within a larger selected area. It works although it is not terribly fast for large selections (think selecting an entire column and then CTRL clicking the header cell... a comment I made in the cited blog article) but it does seem to work.
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 02-09-2020 at 11:57 AM.

  7. #7
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    2016
    Posts
    214

    Re: How to unselect a row within a range?

    Quote Originally Posted by Andy Pope View Post
    In the example the named range, IGNORE_CELLS, can not be selected

    Please Login or Register  to view this content.
    Thanks Everyone! I think this brilliant piece of code from Andy Pope will suit my needs!!!

    for my purposes, I am only concerned with rows, so I would modify this line:
    For Each cell In Target.Cells to 'For Each cell In Target.Rows', and I would put a condition that this would not trigger if the user had selected a column (I have code that detects what the user has selected: rows, columns or cells)

    This is brilliant!! Thanks!

    (tested this and it works beautifully. What an elegant and fast and efficient piece of code!!!)
    Last edited by superlative; 02-12-2020 at 07:38 PM.

+ 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. Replies: 2
    Last Post: 09-14-2016, 09:55 AM
  2. Unselect Range of cells after sort
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2015, 03:50 AM
  3. dynamic named range, but unselect first set
    By amartino44 in forum Excel General
    Replies: 1
    Last Post: 08-16-2013, 02:59 PM
  4. [SOLVED] Unselect Range to top left cell
    By pkew22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-13-2013, 01:49 PM
  5. Unselect Range
    By The Skipper in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2013, 01:08 AM
  6. How to select/unselect range based on variables
    By kirba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-11-2009, 04:00 AM
  7. [SOLVED] Unselect range
    By Biff in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-30-2005, 05:05 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