+ Reply to Thread
Results 1 to 12 of 12

Drop-down list with Directories

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Haarlem, Nederland
    MS-Off Ver
    Excel 2003
    Posts
    10

    Drop-down list with Directories

    Hi All,

    I was wondering if anyone here could help me out with the following, I have little to none experience with VBA. Well, I can do some very basic stuff.

    I would like to have a drop down list in a predefined cell, for example A5. I want the future users of my excel document to be able to click on this drop down list, where a couple of folders will appear, and they can select one folder they need. These folders (no subfolders), for example located in "D:\testomgeving\", will at the moment lead to 4 results. I need these 4 results/folders in the drop-down list.

    I'm sorry for using "I" all the time :-).

    With kind regards,
    Peter de Jong

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Drop-down list with Directories

    Use Data Validation's List. Select a range A1:A4 and enter a name, e.g. Ken. In the Source for the list put =Ken.

  3. #3
    Registered User
    Join Date
    07-01-2013
    Location
    Haarlem, Nederland
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Drop-down list with Directories

    Dear Kenneth,

    Thanks for your reply, but I dont think this is the answer I'm looking for.

    The data's validation list give the possibility for entering text. My goal is to have a drop doen list, consisting of all the directory names in a certain directory. This means that when a new directory has been added, for example "D:\testomgeving\project a", the drop down list will also contain the option "project a".

    Or I dont understand your answer.

  4. #4
    Registered User
    Join Date
    06-27-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    94

    Re: Drop-down list with Directories

    Is your list of directory names automatically generated? or manually typed in every time a new name is added? The data validation can disallow text input and will pop up a message box containing an error if input that doesn't match a directory name is typed.

  5. #5
    Registered User
    Join Date
    07-01-2013
    Location
    Haarlem, Nederland
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Drop-down list with Directories

    I'll give a more detailed example:

    A location contains certain folders/directories, this location is:
    D:\Standard\

    At the moment it has 4 subfolders located in the above location, e.g.
    D:\Standard\apac
    D:\Standard\quality
    D:\Standard\offers
    D:\Standard\custumers

    In the future this list of 4 could expand to 10 or 20 folders, depending on the company changes. But the thing is, I want the drop down list to look for the actual folders at that time. So I was thinking of using VBA ffunctions as xLvalidate and Dir() and Filesystem.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Drop-down list with Directories

    In that Case, put this in a Module after you set the FSO reference:
    Please Login or Register  to view this content.
    And put this in your sheet object. Change A1 (dropdown data validation cell) and ThisWorkbook.Path (parent folder) to suit.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-01-2013
    Location
    Haarlem, Nederland
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Drop-down list with Directories

    Thanks Kenneth, I will give it a try today!

  8. #8
    Registered User
    Join Date
    07-01-2013
    Location
    Haarlem, Nederland
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Drop-down list with Directories

    Hi Kenneth,

    Or maybe someone else who is still reading this.

    This was of great help, but somehow the results mentioned in the dropdown-list are not alphabetically sorted. This would be a big wish for me, because it will make things a lot clearer.

    With kind regards,
    Peter

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Drop-down list with Directories

    Use Split() and Join() for arrays and strings. Put the string from the function that I posted into an array. A simple bubble sort should then suffice. Convert the array back into a string with Join().

    Here is but one example sort routine. I know of many others.
    http://social.msdn.microsoft.com/For...excel-function

  10. #10
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Drop-down list with Directories

    All of my tests sorted my subfolders using my first method. So, I am not sure how much better this will be. Maybe you have Window's Explorer set to sort in an order different than mine.

    I used a vb.net list sorting method here. Windows 8 has v4.5 vb.net framework files installed already. If this does not work then you probably have an old version of Windows with old vb.net framework files without this method.

    I test code before I post so I posted some simple test routines as well. I also showed how to sort either a string or a variant array.

    As before, in an Module:
    Please Login or Register  to view this content.
    In a sheet's code:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-01-2013
    Location
    Haarlem, Nederland
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Drop-down list with Directories

    Thanks Kenneth,
    You have been of great help!
    I must say that when I read all the changes you have made, to just be able to sort alphabetically, it is many steps to just sort.... But that doesn't matter because it works!

    I have a lot more to work on in VBA to achieve my goals at work (I'm HVAC engineer/sales). The goals is to make the quotation process less time consuming. So I can keep asking around on the internet to achieve this goal (some more steps have to be taken), but I also want to become more experienced with VBA. I consider this is a great possibility to enrich my career.

    I'm reading a Dutch book which describes a lot of things like: Sub, With, Loops, etcetera. But the possibilities of VBA seem limitless to me at this moment and I wonder how to ever fully comprehend and automatically (without continuously correcting and searching internet) write codes.
    So:
    1) What is the best way to learn VBA? (Studying and books or problem based learning and asking/looking on internet)
    2) How much time would it cost to be able to master programming VBA, apart from the creative processes you can keep on desiging and designing.

    Kind regards,
    Peter

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Drop-down list with Directories

    1. Depends, what works best for you?
    2. A lifetime.

    To get started, try this:
    http://dmcritchie.mvps.org/excel/getstarted.htm

    Other MVP's like Chip Pearson have excellent resources.
    http://www.cpearson.com/excel/MainPage.aspx

    If you like books, John Walkenbach has some good ones.
    http://spreadsheetpage.com/

    Best way to learn is to teach. Try looking at posts on forums like this and try to solve the problem. There is usually more than one way to solve a problem. Remember, simple code is not always best. Code that is robust will trap known errors. Many solutions can be found by key word searches.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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