+ Reply to Thread
Results 1 to 11 of 11

Data Validation list in a cell through VBA

  1. #1
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Data Validation list in a cell through VBA

    Dear Friends,

    I have assigned a "Named Range" using Offset function. The Name of that Named range is - "Year".

    I wish to create "DATA VALIDATION LIST" in a cell (like in B1, F1, M1) using that Named Range "Year" using macro.

    Therefore, request dear friends to help me.
    Good friends are hard to find, harder to leave, and impossible to forget.

    acsishere.

  2. #2
    Registered User
    Join Date
    12-03-2020
    Location
    Bishops Stortford
    MS-Off Ver
    365/2016
    Posts
    2

    Re: Data Validation list in a cell through VBA

    Where are you stuck/how far have you got?

  3. #3
    Registered User
    Join Date
    12-03-2020
    Location
    Bishops Stortford
    MS-Off Ver
    365/2016
    Posts
    2

    Re: Data Validation list in a cell through VBA

    Attachment 718030
    Attachment 718031

    You should be able to figure this out by recording macros - I would also avoid using names that might be reserved words (eg "Year") in anything...
    Last edited by BenMcBen; 02-10-2021 at 08:23 AM.

  4. #4
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Re: Data Validation list in a cell through VBA

    Sir,

    First, the link in that attachments are not working.

    Secondly, I wish to run a macro that create a "Data validation list" in specific cells.

    When browsed, I found a code, somewhat suitable:

    Please Login or Register  to view this content.
    If I run, the
    Please Login or Register  to view this content.
    is showing error.

    Can any one please help me to modify the code?

  5. #5
    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,915

    Re: Data Validation list in a cell through VBA

    You'd replace the =Animals with =Year but otherwise the code is ok (note that the Formula1 part is not a separate line of code - it's actually part of the previous line due to the underscore at the end of that line). It would be safer to delete any existing validation first using:

    Please Login or Register  to view this content.
    Rory

  6. #6
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Re: Data Validation list in a cell through VBA

    I corrected the code. Still showing error 1004:

    Please Login or Register  to view this content.
    My current macro is:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Pl let me know what correction needed.
    Last edited by acsishere; 02-10-2021 at 09:15 AM.

  7. #7
    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,915

    Re: Data Validation list in a cell through VBA

    Is the worksheet protected? Is the named range correctly defined?

  8. #8
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Re: Data Validation list in a cell through VBA

    Yes, worksheet is protected with a password "a".

    The named range is correctly defined.

  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,915

    Re: Data Validation list in a cell through VBA

    If the worksheet is protected, you can't change the validation. You'll need to unprotect, make the change, then reprotect.

  10. #10
    Registered User
    Join Date
    04-15-2008
    Location
    Tamil Nadu, India.
    MS-Off Ver
    Microsoft Office 2016
    Posts
    582

    Re: Data Validation list in a cell through VBA

    If I completely unprotect the sheet, still the above code is showing that error #1004.

  11. #11
    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,915

    Re: Data Validation list in a cell through VBA

    On which line?

+ 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 - Two Criteria Validation
    By AliGW in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 05-25-2019, 11:48 AM
  2. [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
  3. Replies: 4
    Last Post: 12-19-2013, 10:44 AM
  4. Replies: 3
    Last Post: 05-23-2013, 06:23 AM
  5. Data Validation List - Dependent on Adjacent Cell - Value from Unsorted List
    By justforthis1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-26-2013, 12:24 PM
  6. Replies: 11
    Last Post: 10-06-2011, 02:26 PM
  7. Replies: 1
    Last Post: 10-05-2011, 04:57 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