+ Reply to Thread
Results 1 to 10 of 10

Excel VBA Macro - Limit based on cell selection

  1. #1
    Registered User
    Join Date
    03-18-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Excel VBA Macro - Limit based on cell selection

    Trying to restrict a user from selecting from anything in 3 columns with a data validation list

    Target Range: (three columns L:N) i.e. L3, M3, N3 up to L40, M40, N40.

    Unless a user first populates a field in Column U

    Target Range: U3-U40

    I've tried searching how to lock cell selection unless a corresponding cell is selected for the last few days to no avail. Think the issue is because the target cells aren't actually having a value entered and instead are using a list from conditional formatting.

    Thanks! Andrew.
    Last edited by andytyro; 03-20-2020 at 01:25 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA Macro - Limit based on cell selection

    Did you mean a Data Validation list?

    To install the code:
    • Right-click on the sheet tab.
    • Select View Code from the pop-up context menu.
    • Paste the code from below in the worksheet's code module.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-18-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Excel VBA Macro - Limit based on cell selection

    Hi! Tried this code and nothing happens...

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA Macro - Limit based on cell selection

    Did you install the code in the Worksheet code module as described, and not in a standard code module like Module1?

  5. #5
    Registered User
    Join Date
    03-18-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Excel VBA Macro - Limit based on cell selection

    yes I have, only thing I can think of is this document has heaps of sheets and this sheet is called "Scorecard", but that shouldn't affect anything since the code is in the worksheet

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA Macro - Limit based on cell selection

    It's fairly simple code. Works for me.

    I assume you didn't modify the code?

    Try saving your workbook, closing, then reopen it.
    Last edited by AlphaFrog; 03-20-2020 at 02:04 AM.

  7. #7
    Registered User
    Join Date
    03-18-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Excel VBA Macro - Limit based on cell selection

    still not working, have attached an example file with what I'm trying to do...
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: Excel VBA Macro - Limit based on cell selection

    Hi Andrew,

    You haven't used AlphaFrog's code

    That said, see how this goes:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  9. #9
    Registered User
    Join Date
    03-18-2020
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    5

    Re: Excel VBA Macro - Limit based on cell selection

    thanks robert, i've input the code and it's still not doing anything... really starting to wonder what I'm doing wrong
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: Excel VBA Macro - Limit based on cell selection

    really starting to wonder what I'm doing wrong
    Me too as it's working for me

    Are the macros enabled? Is so are they switched on i.e. is Application.EnableEvents set to True?

    If so try putting a break point (press F9) on the first line of the Shield and run the code again and see what's happening by then stepping through the code (pressing F8).

    I've also included more conditions on the following to only work on columns L to N and rows 3 to 40.

    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. Macro that adds or removes row based ont first cell selection.
    By MaritimeRob in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-20-2017, 01:14 AM
  2. [SOLVED] macro for hiding and unhiding rows based on a dropdown selection and cell value
    By cameldew in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-17-2015, 03:52 PM
  3. Limit dropdown list based on selection from another list
    By msmetal in forum Access Tables & Databases
    Replies: 5
    Last Post: 01-23-2015, 11:22 PM
  4. Macro to delete cell based on active selection
    By M4RSH in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-13-2014, 04:16 AM
  5. Limit Selection to a single cell
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2007, 03:11 PM
  6. [SOLVED] Refedit - Limit selection to only one cell
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2006, 05:55 AM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1