Consulting

Results 1 to 14 of 14

Thread: Deselecting cells

  1. #1
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location

    Deselecting cells

    Hi!

    Is there any way of deselecting the currently selected cells, i.e. setting a workbook such that no cells are selected? I've got my Sheet1 set up as protected, such that no cell may be selected by the user. When I run some of my macros that change some of the cells in sheet1, they leave a cursor after they have finished running. Whenever such a macro runs, I include the code:

    Sheet1.Protect UserInterfaceOnly:=True
    Sheet1.EnableSelection = xlNone

    It's a fairly minor point, more for aesthetic reasons than anything...

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    ?? Do you mean when they select a sheet they can "look at it" only and there is no cells selected while they're viewing it ??

    You could put your own code in the sheet(s) you want to appear that way if that's what you want. e.g.


    Private Sub Worksheet_Activate()
    Sheet1.Protect UserInterfaceOnly:=True
    Sheet1.EnableSelection = xlNone
    End Sub

  3. #3
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Yep, but any cells selected by macros still appear as selected. Like I wrote earlier, it's a query more for aesthetic reasons than anything...

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hello AJS,

    Another option, although I don't know how your worksheet is setup and what your routine is like, would be to make column A hidden and have your routine select A1 (or any row) when done. I realize how speculative this is also.

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    I could be corrected on this, but I thought that there must always be at least one cell selected when you activate a sheet. Even with a new sheet, cell A1 is always selected.

    Could you just select a single cell as the last line of your macro?
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    I still don't understand AJS, I inserted your code as the "last line" in a macro of my own and it did what it should i.e. protected the sheet and 'deselected' all cells.

    If you meant to not have cells selected while the macro is actually running - I don't think it's possible to do this...

  7. #7
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Hi,

    I think you may be right kpuls. If any cells are selected when I load up the workbook, such a selection must be hidden or similar. My sheet is always saved in its protected mode, which I guess has something to do with this. However, the cell E4 appears as selected after running some macros which don't select this or any cells, which I guess means that E4 was selected on startup but that this selection had been hidden from view until then. Does anyone know how I might re-hide this selection?

  8. #8
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Hi johnske,

    I've tried using the aforementioned code as the last line in my macros, but it doesn't deselect/hide the selection for me!

  9. #9
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    I just tried the code here:

    Sheet1.Protect UserInterfaceOnly:=True 
        Sheet1.EnableSelection = xlNone

    And after it ran there were no cells selected.

  10. #10
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Perhaps you're inadvertently selecting the wrong sheet then, try this as your last line instead

    ActiveSheet.Protect UserInterfaceOnly:=True
    ActiveSheet.EnableSelection = xlNone

  11. #11
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Hey Johnske, DRJ,

    Both work, sorta. E4 is still selected, but when I change sheets and change back again, the selection disappears, a la:

    Sheet1.Protect UserInterfaceOnly:=True 
    Sheet1.EnableSelection = xlNo
    Sheet1.Select
    This works also... a little inelegant but I'll take it. Any ideas why I'm having this problem?

  12. #12
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    AJS: As a project manager, I consistently had the guys code worksheet activation events to put the selection at cell a1, and I consistently had them hide column A. firefytr has already suggested this. Unless there's something new in newer versions, and you're using the newer versions, then I'd go that route and save yourself the heartache of trying to figure out another way.
    ~Anne Troy

  13. #13
    VBAX Regular AJS's Avatar
    Joined
    Sep 2004
    Location
    Melbourne
    Posts
    61
    Location
    Yep, probably a good idea dreamboat, firefytr. I've just realised that the cell F4 is completely hidden by an oversized button, so I might park the cursor there...

  14. #14
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    There ya go.
    ~Anne Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •