+ Reply to Thread
Results 1 to 13 of 13

Dynamic Validation From Database

  1. #1
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Dynamic Validation From Database

    Hi All,

    I need some guidance to create a dynamic validation drop-down menu.

    My data source for my workbook is extracted from a MySQL database using the ODBC connection. The problem I have, is that my number of possible unique values to select from my drop-down list can / may change every time I refresh my report. I would need these new options available in my list, but I only want one of each option available.

    If anyone can give me some guidance or a way of doing this, I would really appreciate it. I fear that using named ranges here may not resolve / provide a valid solution.

    Thanks

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dynamic Validation From Database

    MYSQL has a SELECT UNIQUE option, doesn't it? Couldn't you use that to bring back the unique values from a specific field in a specific table?

    Once those unique values appear in your destination column, a dynamic named range using OFFSET() on that column will present those values in data validation based on that named range.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Re: Dynamic Validation From Database

    Unfortunately doing a select Unique will not provide the solution I need, because I still need to return the entire data set. The reason for the drop-down menu is to filter the result on a "Report" page in excel. So the user will be able to, in Excel show only results matching the selected option from their drop-down, but the entire result set will be in the workbook.

    Also, the OFFSET () is not one that I am familiar with although I have seen it. Could you perhaps explain this formula to me and what its used for?
    Last edited by SalientAnimal; 10-23-2014 at 08:06 AM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dynamic Validation From Database

    Yes, SELECT UNIQUE should give you the results you want. I'm not suggesting you bring back less data in your current connection, I'm recommending you set up a second connection that bring back just the unique values into a second sheet.

    Anyway, now that I've heard your answer an even simpler is evident. You can turn on the AutoFilter on the data set you've imported and your users can use the drop down in any column, including the one you're currently considering, and filter by any single value, or even multiple values. Very powerful, handy, builtin, and already includes the drop down you're after.

  5. #5
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Re: Dynamic Validation From Database

    So I've gone with the first option of doing the SELECT DISTINCT in MySQL (Only thing I'm concerned about is running 11 queries on my report, but it works for now).

    The AutoFilter you referring to, is this just were you do a normal filter? Or how does the AutoFilter work?

    Another question I need to add to this is how I am filtering my result on my "Report Sheet". There are 10 possible filter options, however, the formula I am using, only allows my to one filter at a time, I'd like to make all 10 filters valid / usable. I know this can similarly be done using the filter on the dataset, but it doesn't allow for "Nice" presentation of the report. Any suggestions on how to get my formula to do this?

    This is the formula I currently have, but as I mentioned, it doesn't work exactly as expected:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Dynamic Validation From Database

    Yes, I am merely referring to the standard Autofilter. Again your further questions underline its features as desirable as you can use the autofilters multiple filtering options in multiple columns. "Nice" of course is a relative thing, for me "nice" is not having to recreate the wheels already existing in Excel.

    I don't see any problems with the formula posted, what are your expectations of it?

  7. #7
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Re: Dynamic Validation From Database

    The formula I posted is unfortunately only working on the last two options I select.

    Selecting only the very first option as an example doesn't give me any results as all.

    And also, regular filtering will not work here, as this is not the way in which the people want to view the report. The need counts of various criteria.
    Last edited by SalientAnimal; 10-27-2014 at 01:50 AM.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Dynamic Validation From Database

    It's hard to be specific with no sample to look at but I'd suggest you use advanced filter to copy the subset of data you want to a separate worksheet and point all your count formulas at that sheet, or use a pivot table and slicers if you have 2010. As Jerry said, "nice" isn't much of a guide to what you want.
    Remember what the dormouse said
    Feed your head

  9. #9
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Re: Dynamic Validation From Database

    I have attached a sample file for reference. This is what I need the report to look like. Cell F9 is the only cell in the report that currently has the formula that I added to the forum. The other cell formulas are incorrect and I would still need to adjust these.

    I agree with you guys that "Nice" is relative, but to some people they need / want a specific look.
    Attached Files Attached Files

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Dynamic Validation From Database

    You could use a formula like this in E9 (and copied across):

    =COUNTIFS(data_source[Division],IF($C$3="-- Division --","*",$C$3),data_source[Cost Centre],IF($G$3="-- Cost Centre --","<>0",$G$3),data_source[Manager],IF($K$3="-- Manager --","*",$K$3),data_source[Job Description],IF($O$3="-- Job Description --","*",$O$3),data_source[Employment Type],IF($S$3="-- Employment Type--","*",$S$3),data_source[Gender],IF($C$4="-- Gender --","*",$C$4),data_source[Race],IF($G$4="-- Race --","*",$G$4),data_source[Age Group],IF($K$4="-- Age Group --","*",$K$4),data_source[Education Level],IF($O$4="-- Education Level --","*",$O$4),data_source[Service Years],IF($S$4="-- Service Years --","*",$S$4),data_source[Category 1 Q1.1],E$8)

    Note that because Cost Centre is numeric, you have to use "<>0" rather than "*" for all records. You'll also need to add in the filtering for S1 and S2.

    Also note that the * wildcard will only match rows that have some data in the relevant column, so if you may have blank cells in some of the filter columns, that would be a problem with this approach.
    Last edited by romperstomper; 10-27-2014 at 09:14 AM.

  11. #11
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Re: Dynamic Validation From Database

    Thanks, this look to be exactly what I want. Luckily all the fields on my form are compulsory, so I should not have to worry about a blank cell coming into play.

    I just have a question on the date field. Do I use the * Wildcard here? Or do I go with <> ? My Period Field can be 2014, 2015, 2016, etc or ALL. And my date can be a specific month, i.e Jan-2014, Feb-2014, Mar-2014, etc. Just thinking about this, would it be easier to rather just have January, February, March, etc and then to have the Period select determine if there is a specific year? I think If I do it based just on month, I might be able to determine more trends?

  12. #12
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Dynamic Validation From Database

    If the actual data can be numeric or text, I'd use the <>0 criteria.

  13. #13
    Forum Contributor
    Join Date
    12-24-2010
    Location
    South Africa
    MS-Off Ver
    Office 2003; Office 2007; Office 2010 (Prefered)
    Posts
    102

    Re: Dynamic Validation From Database

    Perfect, thanks.
    This is my final solution I have applied and it is working like a charm

    This is the E9 formula. Thanks Again!!!


    =COUNTIFS(data_source[Period],IF($S$1="-- Period --","<>",$S$1),data_source[Month],IF($S$2="-- Month --","<>",$S$2),data_source[Division],IF($C$3="-- Division --","*",$C$3),data_source[Cost Centre],IF($G$3="-- Cost Centre --","<>0",$G$3),data_source[Manager],IF($K$3="-- Manager --","*",$K$3),data_source[Job Description],IF($O$3="-- Job Description --","*",$O$3),data_source[Employment Type],IF($S$3="-- Employment Type --","*",$S$3),data_source[Gender],IF($C$4="-- Gender --","*",$C$4),data_source[Race],IF($G$4="-- Race --","*",$G$4),data_source[Age Group],IF($K$4="-- Age Group --","*",$K$4),data_source[Education Level],IF($O$4="-- Education Level --","*",$O$4),data_source[Service Years],IF($S$4="-- Service Years --","*",$S$4),data_source[Category 1 Q1.1],E$8).

    I originally wanted to use a countifs formula, but didn't know / think about using the Wildcard (i.e the criteria of each criteria range)
    Last edited by SalientAnimal; 10-27-2014 at 10:27 AM.

+ 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. Dynamic Master Database
    By superexcelnub in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-16-2014, 06:40 PM
  2. Dynamic Database
    By Alechko777 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-25-2013, 12:46 PM
  3. Dynamic Database
    By Alechko777 in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 06-24-2013, 07:56 AM
  4. Dynamic Database copying
    By hattisaeed in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2011, 05:01 AM
  5. Dynamic Database Macro/ VB help
    By Cwall9182 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-19-2011, 07:32 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