+ Reply to Thread
Results 1 to 6 of 6

most efficient way to check cell data against 3 known strings

  1. #1
    Registered User
    Join Date
    04-06-2010
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2003
    Posts
    8

    most efficient way to check cell data against 3 known strings

    Ok, so I need to check a cell against three known strings for a match, and I've been trying to work out the most efficient way to do it.

    I was thinking of using select case with a StrComp statement for each case, something like this:

    Please Login or Register  to view this content.
    but I don't actually need the program to do anything if any of the known strings is a match, so the only case that would have any code would be case else.

    I imagine this would work, but it just seems kind of inefficient to have "empty" cases just to check for a match.

    Edit: attached a small dummy worksheet. What I need is to add all the numbers in column C except those described as "DEPOSIT", "W/D" (withdrawal) or "BALANCE" in column B. The descriptions other than those three mentioned generally look the way I've illustrated, with numbers and special characters, and some may also have a couple letters of text as well.
    Attached Files Attached Files
    Last edited by scudder12; 04-10-2010 at 02:06 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: most efficient way to check cell data against 3 known strings

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: most efficient way to check cell data against 3 known strings

    Quote Originally Posted by scudder12 View Post
    but it just seems kind of inefficient to have "empty" cases just to check for a match.
    I often do this.

    Unless you are executing sode 1000s of times in a cycle, in my view, clarity is usually preferable to efficiency. "Clarity" usually equates to "less error prone"


    click on the * Add Reputation if this was useful or entertaining.

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: most efficient way to check cell data against 3 known strings

    You could perhaps store the 3 exception strings in an Array and conduct a Match, eg:

    Please Login or Register  to view this content.
    (assumptions made re: case sensitivity in the above though)

  5. #5
    Registered User
    Join Date
    04-06-2010
    Location
    Rochester, NY
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: most efficient way to check cell data against 3 known strings

    Quote Originally Posted by DonkeyOte View Post
    You could perhaps store the 3 exception strings in an Array and conduct a Match, eg:

    Please Login or Register  to view this content.
    (assumptions made re: case sensitivity in the above though)
    This was the kind of thing I had assumed was possible, just didn't know exactly how to go about it. I would be testing for an exact match on the 3 exception strings, and case sensitivity would be ok. I could always write in some error checking later, it's for my own personal use so no heads will roll if something is off

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: most efficient way to check cell data against 3 known strings

    If you want an exact match (ie case sensitive) using this type of approach you could perhaps revise the Array such that

    a) it includes a Null

    b) is sorted a-z

    at which point you could use an HLOOKUP type approach (w/ binary search) and compare resulting string to criteria, eg:

    Please Login or Register  to view this content.
    (you would need to test for Null also of course)

    I hope that helps.

    EDIT:

    In hindsight - if you wanted to avoid using the Null you could use an Exact Match and Application.HLookup with a CStr, eg:

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 04-10-2010 at 06:16 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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