+ Reply to Thread
Results 1 to 22 of 22

VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

  1. #1
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    I got some great help with this bit of code a while back:


    Please Login or Register  to view this content.
    The range used for the lookup (W6:X25) has now needed to change to this:

    Excel 2016 (Windows) 32 bit
    W
    X
    Y
    5
    Option Subject
    Capacity
    6
    A Ar
    72
    7
    B Ar
    48
    8
    C CP
    24
    9
    D CP
    24
    10
    D ClasCi
    24
    11
    A DT
    48
    12
    B DT
    72
    13
    A Dr
    24
    14
    B Dr
    24
    15
    C Fr
    48
    16
    D Fr
    24
    17
    D FrAI
    24
    18
    C Gm
    24
    19
    D La
    48
    20
    A Mu
    24
    21
    B Mu
    24
    22
    C Sp
    72
    23
    D Sp
    24
    24
    D SpAI
    76
    Sheet: Y9 Options

    The options refer to:

    A D16:D180

    B E16:E180

    C F16:F180

    D G16:G180

    How can I change the code to work on each of these ranges separately? Would the lookup table be better in a different format (this can change if necessary)?

    Thanks for any help!
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Hi Ali

    Would be great if you are able to upload your sample file with all the required information...Especially the values in these ranges...
    A D16:D180
    B E16:E180
    C F16:F180
    D G16:G180
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    I can't upload a workbook at the moment unfortunately, however D16 to G180 looks like this:

    Excel 2016 (Windows) 32 bit
    D
    E
    F
    G
    15
    A B C D
    16
    Dr DT CP Sp
    17
    Dr DT Sp ClasCi
    18
    Ar DT Fr SpAI
    19
    Ar DT Fr ClasCi
    20
    DT Mu Sp CP
    21
    Ar DT Fr SpAI
    22
    Dr Ar Sp La
    23
    DT Mu Gm CP
    24
    DT Mu Sp CP
    25
    Dr Ar Gm La
    26
    Ar Dr Sp La
    27
    DT Dr Fr SpAI
    28
    Ar DT Sp ClasCi
    29
    Dr DT Sp ClasCi
    30
    Mu DT Sp ClasCi
    31
    DT Ar Sp La
    32
    DT Ar CP Fr
    Sheet: Y9 Options

    Here's the thread where I was given the code above: https://www.excelforum.com/excel-pro...tion-list.html
    Last edited by AliGW; 05-01-2019 at 01:45 PM.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Sample workbook now attached with the code I had from the previous thread working. What I want to change is the way that the code looks up the capacity value: the values for each option column can be different. Please ask if anyone needs further clarification. Thank you!

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Perhaps...Don't see the need for a loop
    Please Login or Register  to view this content.
    Last edited by sintek; 05-02-2019 at 03:09 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Thanks - I will give it a go and let you know.

    EDIT: It works perfectly on my sample file - thank you. I will now try to adapt it for the real thing.
    Last edited by AliGW; 05-02-2019 at 03:23 AM.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    OK - so it's not working as I had hoped (sorry - I cannot share the actual workbook, so bear with me).

    I have adapted the code to fit my new layout thus:

    Please Login or Register  to view this content.
    Lookup table:

    Excel 2016 (Windows) 32 bit
    W
    X
    Y
    5
    Option
    Subject
    Capacity
    6
    A
    Ar
    28
    7
    B
    Ar
    48
    8
    C
    CP
    24
    9
    D
    CP
    24
    10
    D
    ClasCi
    24
    11
    A
    DT
    48
    12
    B
    DT
    72
    13
    A
    Dr
    24
    14
    B
    Dr
    24
    15
    C
    Fr
    48
    16
    D
    Fr
    24
    17
    D
    FrAI
    24
    18
    C
    Gm
    24
    19
    D
    La
    48
    20
    A
    Mu
    24
    21
    B
    Mu
    24
    22
    C
    Sp
    72
    23
    D
    Sp
    24
    24
    D
    SpAI
    76
    Sheet: Y9 Options

    Working area (there are entries down as far as row 91):

    Excel 2016 (Windows) 32 bit
    D
    E
    F
    G
    15
    A B C D
    16
    Dr DT CP Sp
    17
    Dr DT Sp ClasCi
    18
    Ar DT Fr SpAI
    19
    Ar DT Fr ClasCi
    20
    DT Mu Sp CP
    21
    Ar DT Fr SpAI
    22
    Dr Ar Sp La
    23
    DT Mu Gm CP
    24
    DT Mu Sp CP
    25
    Dr Ar Gm La
    26
    Ar Dr Sp La
    27
    DT Dr Fr SpAI
    28
    Ar DT Sp ClasCi
    29
    Dr DT Sp ClasCi
    30
    Mu DT Sp ClasCi
    31
    DT Ar Sp La
    32
    DT Ar CP Fr
    Sheet: Y9 Options

    There are currently 30 who have opted for DT in option B, and the capacity for that option is 72, however if I try to change an option in that column to DT, I get the option full message. What have I done wrong, please?
    Last edited by AliGW; 05-02-2019 at 03:56 AM.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Can't see anything wrong offhand...Tried to mock-up a file with the info you have given but no avail...

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,918

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Perhaps:

    Please Login or Register  to view this content.
    Rory

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Of Course...my bad...omitted the Column Ref

    EDIT...Also, forgot to declare
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by sintek; 05-02-2019 at 04:54 AM.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Thanks, chaps!

    Rory - that seems to work - thanks!

    Sintek - I wasn't sure where to put the declaration (sorry - not good with VBA).

    I will test a bit more and see if the code works properly for other columns.

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Its a Dimension statement that can go at the top of your Code.

    Please Login or Register  to view this content.
    it is currently in your code as a variant, however, so you may not need it.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Seems to be working really well - thank you.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Seems to be working really well - thank you
    Are you referring to the corrected aformula = code Post #10

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Sorry, I wasn’t clear - I went with Rory’s variation, but thank you for your help.

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    All good...Post 10 did however solve...

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Yes - it's just that I couldn't get the declaration right, so I tried Rory's, which worked straight off. But thanks once again for your suggestion - I do appreciate it.

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Glad it is sorted...

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Sorry to reopen this, but I have found a slight glitch with the code I ended up using (below). I get a runtime error 13 type mismatch error if I try entering any data into the other columns of the table. How do I limit the range to columns D, E, F and G? In other words, I only want the code to execute if I am accessing cells in the range specified (rows 15 to 150) in columns D to G. Hope this is clear.

    Thanks for any help.

    Please Login or Register  to view this content.
    Last edited by AliGW; 05-25-2019 at 05:41 AM.

  20. #20
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Hi AliGw

    Quite tricky trying to remember what was actually being achieved...
    Please Login or Register  to view this content.

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    81,008

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Perfect - thanks!

  22. #22
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation

    Pleasure...

+ 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] VBA to Prevent Data Entry in Cell with Data Validation List
    By AliGW in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 03-26-2019, 03:02 PM
  2. Replies: 3
    Last Post: 05-09-2016, 08:27 PM
  3. Prevent Data Entry using Data Validation
    By HangMan in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-24-2015, 03:01 PM
  4. [SOLVED] Data Validation: How to clear/delete the content of the cell and not Data Validation List?
    By lukelucky in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-07-2015, 09:42 AM
  5. [SOLVED] Prevent duplicating data when using data validation list
    By amr7 in forum Excel General
    Replies: 2
    Last Post: 02-10-2014, 06:23 PM
  6. Replies: 4
    Last Post: 12-19-2013, 10:44 AM
  7. Data validation to prevent duplicate entry.
    By vishu in forum Excel General
    Replies: 0
    Last Post: 03-14-2005, 08: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