+ Reply to Thread
Results 1 to 13 of 13

Determine with VBA which Area has been selected

  1. #1
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Determine with VBA which Area has been selected

    I’m using a BeforeDoubleClick event to enter a check in the cell selected with the event below.

    Please Login or Register  to view this content.
    There are four columns of data with column A holding different area of data (four areas in this case). In each area there needs to be one check which the user can get with the event above.

    Here’s what I can’t quite figure out. If the user wants to swap the check for another cell within each area, how can we delete the previous check and add the check to the new cell. Actually, I probably got the adding of the new check as it’s the target, but not sure how to remove the previous check from that one area.

    So in the attached example, the first area is A2:A9. The check is currently in D6, but the user wants to change it to D8 so D6 needs to be cleared. The other three areas were not messed with so their checks should stay as is.

    I’ve been researching the .Areas in VBA but can’t understand how to narrow the focus to the area affected.
    Attached Files Attached Files
    HTH
    Regards, Jeff

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Determine with VBA which Area has been selected

    Couldn't you clear all the checks in the area and then put a check in the appropriate cell?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    Maybe this will work for you, or give you some ideas:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Determine with VBA which Area has been selected

    Thanks Trevor and Norie. I was indeed over complicating the matter. Both of these worked great.

    Even though I've been on this forum for many years, you guys still amaze me at how well you know your way around this stuff.

    Thanks again for your time...

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    You're welcome. Thanks for the rep.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    Modified version to cater for initial setup:

    Please Login or Register  to view this content.
    Without this modification, the code will fail if there are no ticks present, that is, when you first start the selection process.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    And, in that respect (if not others), Norie's solution is the better one

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Determine with VBA which Area has been selected

    Thanks Trevor for the update.

    I can see how you might say Norie's solution is better and indeed it's spot on, but your code gives me another angle and solution to ponder in an attempt to improve myself.

    I'd rather have a couple of sound solutions than none at all
    Last edited by jeffreybrown; 01-20-2018 at 06:14 PM.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    Again, you're welcome.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Determine with VBA which Area has been selected

    Trevor

    My solution relies upon the named ranges Range1, Range2 etc existing, if they don't then it's kind of useless.

    I was going try to write something a bit (lot really!) complicated until I found those named ranges - might have a go at that tomorrow.

  11. #11
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Determine with VBA which Area has been selected

    Hi Norie,

    You are spot on. The first way I attacked this was with 4 named ranges (Range1, Range2, Range3, and Range4).

    I would be interested in seeing how you can do it without named ranges and by using the areas collection.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    My solution doesn't use Named Ranges, it just uses the values in column A as "groups".

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: Determine with VBA which Area has been selected

    @Jeffrey: thanks for the feedback. Been playing around with this and, hopefully, an improved version:

    Please Login or Register  to view this content.

+ 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. Determine if cell in last table row is selected
    By michellepace in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2015, 03:01 AM
  2. How to determine word selected from listing
    By Shermaine2010 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-30-2012, 03:10 AM
  3. Determine print area for all sheets
    By pvp in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-31-2012, 10:41 AM
  4. How to determine what Cell was selected
    By chamdan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-02-2009, 12:28 PM
  5. Determine a techs general area.
    By oneyejack in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-24-2007, 09:20 PM
  6. I need to use area code to determine time zone
    By Dick in forum Excel General
    Replies: 1
    Last Post: 07-11-2005, 01:05 PM
  7. Determine area under a curve in Excel
    By Ken in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-22-2005, 12:06 AM

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