+ Reply to Thread
Results 1 to 11 of 11

vba cascading dropdown list with free text entry option

  1. #1
    Registered User
    Join Date
    02-28-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    vba cascading dropdown list with free text entry option

    Dear Forum,

    I have been trying to code a data validation drop-down list. The reason I am using code is that the list is a cascading list that may require free text entry depending on choices selected.

    The basic premise of the code:

    If user selects "Site" as "Company" then they are presented with a drop-down and a cascading drop down list.
    If user selects "Site" as "Third Party" or "Customer" they are presented with a free text field to enter "Location"
    There are a few nuances if the user selects US or another country in that "N/A" gets populated into the region field for non-US.

    Issues
    • I keep getting an error when I select "Company".
    • Not sure if “Case” is correct approach or do I use “If else” statements, or can both be mixed?
    • Formula1 needs to reference the correct row. I've tried using ThisRow in the formula for the indirect statements but just get errors every time.

    Code.jpg

    Any guidence would be appreciated.
    Thanks

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: vba cascading dropdown list with free text entry option

    welcome to the forum

    In future always post your code as text (not a picture) - if you click on the # icon first and ensure that the cursor is
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 03-01-2017 at 06:43 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    02-28-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: vba cascading dropdown list with free text entry option

    Hi and thank you for speedy reply. Apology for the picture but I was getting firewall block message with the code enserted as per instructions. Couldn't figure out what I was doing wrong so resorted to the image

    Good to learn that "case" route was right way. How does one choose one approach over another?

    A key issue is that that the validation code for "Company" case is failing. The code construct looks exactly as per reference manual. Could this be due to invalid selection error (I would click to ignore) if entering the dropdown manually? Do I need some error routine here to ignore that?

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: vba cascading dropdown list with free text entry option

    You did nothing wrong. The firewall is very necessary but it takes exception to certain unexpected things.
    - one of its may dislikes seems to be "<" ">" - try putting spaces around them. It may work if it's not a Wednesday and the sun is shining.


    How does one choose one approach over another?
    They pretty much do the same thing, but select case tends to look cleaner and more succinct.
    I tend to use both together if there are lots of conditions inside other conditions - visually the code is easier to read.


    the validation code for "Company" case is failing
    - which error code are you getting?
    - which line is the code really stopping at?
    - have you stepped through the VBA with {F8}?
    Last edited by kev_; 03-01-2017 at 10:12 AM.

  5. #5
    Registered User
    Join Date
    02-28-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: vba cascading dropdown list with free text entry option

    Sorry for delay.

    The error flags this line but not every time. I changed selection 10 times in a row and it didn't happen. Then it occured 5 times in a row and I reset all the cells to original values and it started to work again (but multiple rows).

    < code > .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=IF(I5=""US"",INDIRECT(J5),INDIRECT(I5))" < /Code >

    This code is referencing criteria in I5 to get cascade drop down based on value in J5.

    The error is:

    Run-time error '1004': Application defined error or object defined error

    Do you think its because I'm testing it static on line 5 (as test) but the wrap around code is referencing multiple rows?

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: vba cascading dropdown list with free text entry option

    Apologies, but most of my attention is currently on a large project - I will get back to you in 2 or 3 days.

    I can't test your code due to your posting difficulty (post#1)
    In the meantime, perhaps you could attach your workbook including valid data and your code.
    To attach a file - click REPLY ... GO ADVANCED ... look below for MANAGE ATTACHMENTS etc

    ManageAttachments.jpg

  7. #7
    Registered User
    Join Date
    02-28-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: vba cascading dropdown list with free text entry option

    Thanks. Hold fire... I will upload a copy of my worksheet on Friday.

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: vba cascading dropdown list with free text entry option

    That's fine - but I will be unable to give this any time after Friday for around 10 days - so to give me time to look I would appreciate it if you could upload it early Friday morning
    thanks

  9. #9
    Registered User
    Join Date
    02-28-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    5

    Re: vba cascading dropdown list with free text entry option

    Example file uploaded
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: vba cascading dropdown list with free text entry option

    It took me around 70 selection attempts to get it to error once!
    And then it went away again....
    It's a bit of a puzzle....
    I cannot re-create the error now..200 selection attempts without any error .

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: vba cascading dropdown list with free text entry option

    I have amended your code slightly but it is essentially the same as yours
    Variable "myFormula" added to hold the formula
    It should make no difference - but the code did not fail once for me after this change
    I have tested with both 2010 and 2016 and get the same results



    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. [SOLVED] Dynamic cascading dependent dropdown list
    By kevivu in forum Excel General
    Replies: 4
    Last Post: 03-26-2016, 12:24 PM
  2. Replies: 0
    Last Post: 03-17-2014, 02:11 PM
  3. [SOLVED] Cascading dropdown lists all tied to first dropdown
    By ruthl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-18-2012, 08:03 PM
  4. Tag clouds using free-form text entry (single column)
    By knaledge in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2012, 04:28 AM
  5. Replies: 1
    Last Post: 01-06-2012, 05:55 PM
  6. Cascading dropdown list with dynamic ranges
    By devunow in forum Excel General
    Replies: 3
    Last Post: 11-04-2008, 09:56 AM
  7. Stopping free text entry in validation cell
    By smf in forum Excel General
    Replies: 2
    Last Post: 12-15-2005, 03:50 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