+ Reply to Thread
Results 1 to 15 of 15

Nested CONTAINS within IF(COUNTIF()) for complex database

  1. #1
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Angry Nested CONTAINS within IF(COUNTIF()) for complex database

    Hello, all

    I have bit of an interesting Bug in my database. My database has over 13700 rows by 5 columns. I am using a search button that utilizes both macros and formulas. I wrote a formula to allow me to search all the columns at the same time. I have a column labeled basic description and there is both numerical and text data within this column.

    Desired result:
    I want to be able to search the entire database only using pieces of information. I want to be able to do a partial search and have a match. If the data in a cell is "the good brown dog" i want to be able to search "good dog" or "the brown" and it populate the cell "the good brown dog" as a search result.

    I had this previously working however using the contains function on column H but it limited me to be able to only search data in column H. I need to be to do a partial search across all the columns and rows in the document.

    The formula used is =IF(COUNTIF(F9:J9,"*"&$H$2&"*")>0,1,0).. I need a contains function built into this to allow me to search contains parameters in F9:J9

    Please open the database below and do a search "wrench insert (modified)". I want to be able to search "wrench (modified)" and have the same search results. but through this, I must still have the ability to search all the columns as well.

    Thank you
    Attached Files Attached Files
    Last edited by Cont-Kevin; 06-14-2017 at 02:41 PM.

  2. #2
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    this UDF was used

    Please Login or Register  to view this content.
    Last edited by Cont-Kevin; 06-14-2017 at 01:02 PM.

  3. #3
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    It probably would've been wise to continue this in the old thread:

    https://www.excelforum.com/excel-for...arch-tool.html

    Nevertheless, the original CONTAINS was designed for a one cell range. The version below should work on larger ranges:

    Please Login or Register  to view this content.
    It works like SEARCH, so use CONTAINS(SearchTerm, SearchedRange) to return the number of cells in the range that contain all of the search terms. The formula in B9 uses:
    =CONTAINS($H$2,$F9:$J9)

    H3 should be changed to:
    =COUNTIF(B9:B169,">0")

    And your new Search macro should also be adjusted to account for values greater than one:

    Please Login or Register  to view this content.
    Try out the attachment to see if it's working as desired. Please also try to edit your post to include [CODE] tags around the code you posted above. If you're quick, you can fix it before the mods tell you to.
    Attached Files Attached Files
    If your problem has been solved, please use "Thread Tools" to mark the thread as "Solved".

    If you're grateful for this site's existence and would like to contribute to the community, please consider posting something hilarious in our joke thread:
    https://www.excelforum.com/the-water...ke-thread.html

  4. #4
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    CAntosh you are a true Excel Wizard! Thank you so much!
    Last edited by Cont-Kevin; 06-14-2017 at 01:39 PM.

  5. #5
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    I see what you mean about the issue with no search term in H2 producing a zero when it should return every entry. This occurs because the CONTAINS function regards a blank as a null search entry, so it returns 0 matched rows. The simplest work around is to include an IF clause for a blank search box, so H3 would be:

    =IF(H2="",COUNT(B9:B169),COUNTIF(B9:B169,">0"))

    I'm afraid I'm not sure where the 13693 expectation is coming from? Your sample workbook includes entries from row 9 through row 169, so the total in H3 wouldn't exceed 161, by my understanding. With the formula above, I get a correct "161" for a blank H2. I also get a correct "161" for a hyphen in H2. What am I missing? Is 13693 the number of rows in the actual workbook? What incorrect result are you getting for a hyphen in the search box?

  6. #6
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Yes thank you! Apologies. I have been working in so many excel sheets they are blending together. The version on this website is only a small portion of my main file due to file upload requirements. My document has over 13700 rows and what I have been doing is tearing your document apart to implement into mine and get it working. This way my document works and I also learn your logic behind your solutions. I greatly appreciate all of your help with my buggy document!

  7. #7
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Hello CAntosh. If I can bother you for one more favor. Would you mind writing me a macro that would reset the any search terms in cell H2. This will be tied to a button that when clicked will reset H2 and repopulate with no search terms. Thank you.

  8. #8
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Are you sure you need one? Clicking 'delete' on H2 will clear the search box. With the "search" macro in post #3, clicking the search/refresh button with an empty search box will return the entire list.

  9. #9
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Yes, my boss requested to have a physical reset button to reset the values in H2. And upon that reset the full data list to populate. so i thought i could use a macro to set the cell value to "" when clicked

  10. #10
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    If you decide you need one, the macro below should clear H2 and unfilter your table:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Awesome! you are incredible!! How can I enable these macros even if there is protection on the sheet? Because when protection is enabled it says you have access to this command due to the protection.. Do you happen to know a work around for this?

  12. #12
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    If I'm understanding you correctly, then you can enable macros on the computers that will use the workbook by clicking file > Options > Trust Center > Trust Center Settings > Macro Settings > Enable all (or something similar). Be aware that this may also expose you to malicious macros, as well, though, so be careful what you open.

  13. #13
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    I figured it out. When you use protection on sheet all your macros are disabled even if you enable macros to operate in the trust center settings. If must have a code at the begging and end of your function to allow them operate under protections. The way it works is, it sets the function with permissions to bypass the protections upon clicking, however this occurs only once and stays unprotected; so enabled protection again will continuously maintain your documents protection however enable your macro buttons. The codes can be found below also with an example.

    Use this at the start of your code ( after your declare the function):
    Please Login or Register  to view this content.
    Use this this at the end of your code (before you declare end):
    Please Login or Register  to view this content.
    Example Code:
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Correct, that should work. I misunderstood your question as relating to enabling macros, instead of protecting sheets. I should read more carefully. Your solution is a good one, just be aware that anytime the password changes, you (or someone) will need to go into the VB Editor to update the code. It's also worth noting that a savvy user could open the VB Editor and learn the password that's meant to protect the sheet. Those two caveats aside, the protect/unprotect lines should do the trick.

  15. #15
    Registered User
    Join Date
    06-09-2017
    Location
    USA
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: Nested CONTAINS within IF(COUNTIF()) for complex database

    Well its funny that said a savvy VB user could just edit the code and see the password. I found a setting that locks your VB code so you cant see any code until you type in the password. If you go to the tools drop down menu and click "VBAproject Properties" and slide over to Protection. Then you can set a password that doesn't allow anyone to view any VBA code unless the password is entered!See the picture below: hehe.png
    Last edited by Cont-Kevin; 06-15-2017 at 11:37 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. Countif with nested if
    By darkzero901 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-13-2013, 05:34 PM
  2. help on a nested countif/nested if formula
    By vickiemc in forum Excel General
    Replies: 2
    Last Post: 08-13-2008, 08:29 AM
  3. nested COUNTIF maybe?!
    By rjmills18 in forum Excel General
    Replies: 2
    Last Post: 08-06-2008, 08:43 AM
  4. Nested COUNTIF
    By vioravis in forum Excel General
    Replies: 1
    Last Post: 06-28-2007, 01:59 AM
  5. Nested Countif
    By tuck80 in forum Excel - New Users/Basics
    Replies: 13
    Last Post: 02-01-2007, 07:44 PM
  6. Using nested IFs with CountIf
    By Excel novice in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-12-2006, 06:40 AM
  7. Nested countif?
    By saskin23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-10-2005, 12:53 PM
  8. Nested Countif
    By matasw in forum Excel General
    Replies: 2
    Last Post: 02-09-2005, 03:30 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