+ Reply to Thread
Results 1 to 8 of 8

Macro to search a range with multiple combined values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Macro to search a range with multiple combined values

    Hi All,

    I’m back again looking for help in how to set up the following formula code.
    I need to count the number of times in col K (K5:K105) any of the following is entered:
    "AV", "BT", "RLCCC", "RLCMO", "RLFW", "RLHCC", "RLHMO", "RPCCC", "RPCMO", "RPHCC", "RPHMO", "TA" And matches one of 8 values listed in col AD rows 5 thru 12. I am thinking that part of the code would use a case or array but am not sure on how to set it up. I have the entire code listed if someone can figure out why my code is giving unstable count results.

    I had this code listed below but it does not give accurate count seems to give counts from 3 to 6 for one actual entry.
    'If value of col K equals "AV", "BT", "RLCCC", "RLCMO", "RLFW", "RLHCC", "RLHMO", "RPCCC", "RPCMO", "RPHCC", "RPHMO", "TA" and
            'L in same row equals AD5 then AE5 is increased by 1
            If Range("L" & Srn) = Range("AD5") Then
                Select Case Target.Value
                    Case "AV", "BT", "RLCCC", "RLCMO", "RLFW", "RLHCC", "RLHMO", "RPCCC", "RPCMO", "RPHCC", "RPHMO", "TA"
                        Range("AE5") = Range("AE5") + 1
                End Select
            End If
    I have attached the full workbook if anyone can find out why my code is giving inaccurate results. Thank you for all help in advance.
    :confused:

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Macro to search a range with multiple combined values

    You have this as a part of Worksheet_Change event handler.
    My suggestion is to add at beginning of the code (before any cells are modified)
    Application.enableevents = false
    and just before end sub (if you exit from handler with exit sub - before this command(s) too)
    application.enableevents = true
    otherwise when you for instance change AE5 - worksheet change event handler is again called
    Best Regards,

    Kaper

  3. #3
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Re: Macro to search a range with multiple combined values

    Thank you for your help. Well now I am really confused about what is happening. When I put your suggested code into beginning and end on the first entry into the first column everything stops, and no error code is given. The code was working except for the erroneous calculations for what I originally stated. Can you give me any guidance on what may be happening please? Your help is appreciated.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Macro to search a range with multiple combined values

    Have you tested it like:
        
        If Target.Cells.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
    Application.enableevents = false

    or
    Application.enableevents = false
        If Target.Cells.Count > 1 Then  
              Application.enableevents = true
              Exit Sub
        end if
        If Target.Value = "" Then 
              Application.enableevents = true
              Exit Sub
        end if
    Last edited by Kaper; 10-30-2017 at 09:23 AM. Reason: typo in tested - was "esed" - probably not easy to understand

  5. #5
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Re: Macro to search a range with multiple combined values

    When I try to run it with the first code you listed above it just goes into never-never land, no functions run. I can enter data but it will not run any of the code. It also doesn't give any errors. If I don't have it turned on it will run but gives me bad numbers for the ATR count. It gives different values with every entry, sometime it gives 3 then next time it may be 5, etc. I tried to put a message box between every calculation in the code but it does the same thing and jumps some steps and then stops at different steps. I don't know where to go from here. Thanks again for your help.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to search a range with multiple combined values

    How about posting a sample with some reasonable data??
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Re: Macro to search a range with multiple combined values

    I have attached the workbook with sample data.I have labeled what each section of code should do when working properly. Sheets also have sample data that should be placed on them. Thanks again for your help.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    06-06-2017
    Location
    Phoenix, AZ
    MS-Off Ver
    2013
    Posts
    129

    Re: Macro to search a range with multiple combined values

    Hi all,
    I am just checking in to see if anyone has any instruction for me on how to check for errors in my code. The code is included in the workbook. I see the workbook has been viewed 4 times. I do appreciate all help received.

+ 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] Macro to compare Sheet2 values with Sheet1 cells range (combined with Name Manager)
    By Manish_Gupta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2014, 08:26 AM
  2. Combined IF ISNUMBER SEARCH for multiple words
    By caffegelato in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-16-2013, 08:57 AM
  3. [SOLVED] Directional Row Search Macro for Multiple Values
    By swilkinson1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-14-2012, 11:20 AM
  4. Macro to return multiple values from search value
    By Mr Low in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2012, 02:00 PM
  5. Search for multiple range values in another range
    By kuleox85 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-10-2012, 10:23 PM
  6. Search named range for multiple matches to critera and return date & values
    By a.mack123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2011, 10:07 AM
  7. Macro to search multiple values and delete rows.
    By BigSlick in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-05-2008, 04:38 PM

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