+ Reply to Thread
Results 1 to 12 of 12

Insert validation list with =INDIRECT in VBA

  1. #1
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Insert validation list with =INDIRECT in VBA

    Hi all,

    i have the following part of a script.

    Please Login or Register  to view this content.
    It creates a copy of the selected line, and paste it 1 row under.
    I would like to let range E20 (after running the script) create a validation list with INDIRECT function, which refers to range C17.

    Do any of you have a clue to script this?

    Regards,
    Crispy85

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert validation list with =INDIRECT in VBA

    Can you clarify what your Validation cell should contain.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Insert validation list with =INDIRECT in VBA

    Hi Richard Buttrey,

    I hope you can follow me because i have a hard time explaining it. I work with validation list via =INDIRECT function.
    whenever i add an extra line, the =INDIRECT will shift for example from =INDIRECT(C17) to =INDIRECT(C18).

    Now, i would be able to fix the range with $C$17 but as you will see in my example sheet, it won't do what i want...

    What i would like is = if line inserted, fix the indirection range so it won't shift.

    But i don't really know how to script this
    Attached Files Attached Files

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert validation list with =INDIRECT in VBA

    Hi

    I don't understand your comment re C17 on the sheet. The data validation currently uses INDIRECT(C17). If you change that and make row 17 absolute (i.e. INDIRECT(C$17) ) then when copied the copied validation will still refer to C17.

    And you seem to be asking for something different with E20 suggesting it should not refer to C24. What should it refer to?

    Incidentally there's no need for all the .Select statements. For instance your first Case statement could simply be


    S
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Insert validation list with =INDIRECT in VBA

    Hi S,

    Thanks for your help so far.
    As i said, i'm having a difficult time explaining it so your help is much appreciated!!

    There can be an unlimited amount of domains and each time a new "domain" is created it does so by copying and inserting row 1:6 in row 16.
    So in cell E4, data validation is set to list =INDIRECT(C2). So when the new "domain" is created it sets it in Cell E19 with =INDIRECT(C17). That's the reason why i can't make it absolute, because then it will always refer to $C$2. Do you understand what i mean?

    So the easiest way to fix this (i think) is:

    Whenever Add line 1 or Add line 2 is clicked, it inserts a line above, but in the one that is under the inserted one, it should change the reference to absolute.
    So in my example sheet. When the link Add Line in I10 is clicked, a new line will be inserted in row 19. The existing row 19 will go down 1 row and it's reference to C17 should be made absolute.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert validation list with =INDIRECT in VBA

    HI,

    It might be easier if you mock up a before/after example and in the after example manually add the results you expect to see.

    So run whatever macros you want to run to create extra lines. Then copy that sheet by right clicking the tab name and choosing copy, then manually edit the copy so that we can see the end goal.

  7. #7
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Insert validation list with =INDIRECT in VBA

    Maybe this will help so you can see what my problem is, when you follow these steps:


    1. Click ADD DOMAIN in I11 3 times
    2. Click C17 and choose "ABC"
    3. Now the dropdownlist in E19 is activated
    4. Pick a option from the list
    5. Now click ADD LINE in I10
    6. The dropdown list that was first in E19 and now in E20 doesn't work no more.

    Thanks
    Crispy85

  8. #8
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Insert validation list with =INDIRECT in VBA

    Hi S!

    I now added the sheet3, with what the result COULD be like (depending on how many domains and extra lines are inserted.)

    all the dropdown lists in column E refer to their "domain".

    Many thanks.
    Attached Files Attached Files

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert validation list with =INDIRECT in VBA

    Hi,

    Maybe it's me, but when I change the data validation in say E26 from =INDIRECT(C24) to Indirect(C$24) and then click the Add line, the new line I get does still have the data validation formula =Indirect(C$24)

    Isn't this what you want? Your sheet 3 suggests it is.

  10. #10
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Insert validation list with =INDIRECT in VBA

    Hi S,

    Yeah, You are correct and that's the way it should be.
    However, the "ADD DOMAIN" option, copies and inserts row 1:6 in row 16. So how would this work? In cell E4 the data validation will be set to Indirect(C$2). When "ADD Domain" now is clicked, it keeps the validation Indirect(C$2) while it should be Indirect(C$17).

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Insert validation list with =INDIRECT in VBA

    Hi

    In your macro CASE I11 after the Rows("16:21").Hidden = False enter the following two lines.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Insert validation list with =INDIRECT in VBA

    Hi Richard,

    Unfortunately, this doesn't fix it
    What it does with your given formula is just make a dropdown list with the info filled in in cell C17.
    It should make a dropdown list with ABC or DEF or GHI depending on what is been chosen in C17.

+ 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] data validation indirect where multiple values show specific list
    By skip2mylew in forum Excel General
    Replies: 4
    Last Post: 02-09-2014, 05:35 PM
  2. INDIRECT.EXT and List using Data Validation
    By jimmyyap in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-02-2013, 03:12 PM
  3. Replies: 3
    Last Post: 11-07-2012, 10:26 AM
  4. Vlookup from conditional indirect data validation list
    By mmckay in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-21-2011, 08:54 PM
  5. [SOLVED] Indirect formula using Data Validation List of Worksheet Tabs
    By Scott in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-05-2005, 11:10 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