+ Reply to Thread
Results 1 to 6 of 6

vba excel -- having issues with INSTR and Like functions

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    vba excel -- having issues with INSTR and Like functions

    I have some strings:
    Please Login or Register  to view this content.
    I have a datasheet from an outside source that outputs data with the attribute names within the numeric data itself (smh).On top of this, the data headers are not even consistent, and some sources have 1 range of data and others have multiple columns, so I've been tasked on munging and compiling all these disparate sources into one table. Luckily they're all csv files. I remove the alpha characters once I've identified the address of the data range, but I've been trying to use Instr and Like to locate the first instance using the predefined sAttribute() values. Once I have the address, I can then remove the string variables from the numeric data easily and got that working fine; however, I can't get my initial procedure to match the partial string. For example, a data source comes with a 'ppb' suffix attached to all the data and I want to look the first instance of sAttribute(1). I've tried using wildcards and it still doesn't work.
    Please Login or Register  to view this content.
    I've also tried using with no success:
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: vba excel -- having issues with INSTR and Like functions

    When using Like the wildcards should be applied to the string you are searching for.

    So if you wanted to find if A1 contains 'pbb' you would use something like this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel -- having issues with INSTR and Like functions

    Ok that makes sense. So what if Range("A1").value is 'pbb' and the search criteria (after the Like) has a 'tvoc_' in front of the 'pbb', how do I rectify those initial characters within the search criteria? Or say that a value in A1 has a string of characters before and after what is being searched. For example if the value in A1 is -465.3 ppbAc* and my search criteria is 'tvoc_ppb'. Is this possible without having to do some manual formatting?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: vba excel -- having issues with INSTR and Like functions

    If the search criteria is 'tvoc_ppb' then surely '-465.3 ppbAc*' isn't a match?

  5. #5
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: vba excel -- having issues with INSTR and Like functions

    Hello Norie. I guess I'm not wording it correctly, I'm looking for only a partial match. That being, any value that has the letters 'pbb' in it, in that order. The value could have other superfluous characters in it.

    I guess I could change the search criteria to just 'ppb' and then include another condition later down the line that would change range header to 'tvoc_ppb'. But I'm more curious if there is a way to find a match, partial or otherwise, of a string using only a partial string as the criteria, or does the criteria need to be absolute?

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: vba excel -- having issues with INSTR and Like functions

    How is the code supposed to know that it should try and match just the ppb part of the tvoc_ppb search criterion?
    Rory

+ 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. FIND functions issues
    By vinnyt514 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-29-2017, 04:46 PM
  2. [SOLVED] Excel formula nested functions max, if, and multiple criteria issues
    By Jack7774 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-19-2016, 04:38 PM
  3. Issues with InStr
    By roneys in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2016, 02:36 PM
  4. Left and Instr functions together?
    By MeggieDoodles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2015, 03:19 PM
  5. using InStr and Mid functions
    By bbhockey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2015, 01:09 PM
  6. LOOKUP functions issues
    By stanemenike in forum Excel General
    Replies: 3
    Last Post: 11-20-2014, 11:00 AM
  7. IF Functions and Matching issues
    By wilson32294 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-21-2013, 02:18 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