+ Reply to Thread
Results 1 to 5 of 5

vbTextCompare not performing as expected in vba

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    vbTextCompare not performing as expected in vba

    Hey all, the cell can contain a number of values (e.g. &W, &H, & , etc). If the test passes, then that means the current string in the cell contains one of the above delimiters. The problem is when I grab the secondary name (the name to the right of the delimiter), part of the delimiter remains because the delimiters contain different character lengths:

    cell c output:
    W abc c def
    H abc c def
    abc c def
    abc c def

    original data in cell A:
    abc a def &W abc c
    abc a def &H abc c
    abc a def & abc c
    abc a def &abc c

    what I want in cell C:
    abc c def
    abc c def
    abc c def
    abc c def

    The code:

    Please Login or Register  to view this content.
    I was trying to use vbTextCompare to check if the cell contains " &", and if so subtract 1 from the value of pos, but otherwise subtract 2, but it doesn't appear to be doing that.

    Thanks for response.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: vbTextCompare not performing as expected in vba

    johnmerlino,

    Can we see your workbook and macro code?

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, click on the New Post button, then scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,636

    Re: vbTextCompare not performing as expected in vba

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: vbTextCompare not performing as expected in vba

    After taking a break I realized why the vbTextCompare wasn't working. It was comparing for " &" which all the cells contained, so I had to limit it by the pattern i wanted to targed:

    Please Login or Register  to view this content.
    Also I think the answer above misunderstands what I am trying to do. This:

    Please Login or Register  to view this content.
    split will return a new array with the extracted contents and then it returns index position 0, which would be the main name. But The issue I was having was the secondary name where part of that name is extracted from main name.

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,636

    Re: vbTextCompare not performing as expected in vba

    Does that mean that you solved the problem? If not then:
    Please Login or Register  to view this content.

    Notes:
    1. Your original post gave a sample of the original data in column A and a desired output for column C that looked like the LEFT side of the original data.
    2. The Split function, in your case, gives just a two element array with index zero holding the left side of the original data and index one holding the right side.
    3. Once the original data is broken at the ampersand, the test for the remaining delimiters is accomplished with a small test loop.
    Last edited by protonLeah; 07-10-2011 at 03:02 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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