+ Reply to Thread
Results 1 to 6 of 6

Compare multi-line text cell to data in much larger text file

  1. #1
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Compare multi-line text cell to data in much larger text file

    I have been working in and created a spreadsheet with tons of macro code to help create command scripts that I use to configure routers.
    During my data research, I will locate a block of text within a large text file and copy that to a cell within my sheet. The general layout is each row contains all data related to a specific customer. Each column will contain specific types of data for all customers. What I need to be able to do is take one cell of multi-line text and compare it to the original text file (which might contain updates that I need to catch). So, I need to search within a large text file to match several lines of text from one cell, where one or more lines of text in that cell may not match the entire relative area in the larger text file. It may be just enough to find/match the entire cell with the complete text data. If I can't match the entire cell, I'll replace it completely with what I will have to manually find anyway. I hope I asked this properly.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Compare multi-line text cell to data in much larger text file

    Maybe you could do something like:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Compare multi-line text cell to data in much larger text file

    This is sort of working. I can see how it is a start in the correct direction. Obviously I had to change to reflect where my source data and text file are, but that's ok.
    One thing I don't understand...
    In this line:
    Please Login or Register  to view this content.
    the resulting array has only one line/element [str(0)]. If I change the 'vbNewLine' to 'vbLf', the array does have each line from the source text [Str(0) through Str(n)].
    But it appears to fail the compare. If I leave it as 'vbNewLine', the For-Loop does nothing, since there is only Str(0); which does have the complete text from the cell.
    ---
    So, I may have asked my question incorrectly. Imagine I have several pages from a book. Each paragraph is copied to one cell (with vbLf for EOL). I get a new text file with corrections that may have adds, changes or deletes for any individual paragraph. Some paragraphs will not change, but some might. So, any paragraph that does not completely match the cell should pop an error. I have other ways of detecting new paragraphs, so that isn't required. But, if a paragraph is gone, I need that to alert as well, just as if a paragraph has a minor edit within.
    ---
    Perhaps asking a complete question is helpful?

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Compare multi-line text cell to data in much larger text file

    Regarding vbnewline and vblf constants, they both do the same thing in essence but are nto equal to each other. So vbnewline worked for my test data but I created that with the vbnewline for end of line....

    If youhave already changed to vbLF though, I would have expected that to work as you want. Maybe if you uploaded a workbook and text file with an example of your data that would help get a solution for you?

  5. #5
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Compare multi-line text cell to data in much larger text file

    I believe I have changed directions to perhaps a more efficient way to do this.
    There is a thread that leans in the direction of what I'm trying:
    http://www.excelforum.com/excel-prog...ion-match.html
    ---
    I'm opening my text file into an array. Searching in that array appears to be blazing fast.
    Using a combination of Filter() and Application.Match() seems to be doing what I need, but the value from A.M() is only the first hit.
    I can use Filter() to build a small array to know how many times my search string exists. If I can get Filter to also tell me which lines, I'm almost done.
    I need to deal with multiple hits for the string for which I am searching.
    When Application.Match hits my first search value, I can look up and down in my text array for what I need.
    After I find the data around my first hit, I need to jump to the next hit that has the identical text match and deal with what I find there.
    If I want to waste CPU cycles, I could just for/next through the entire array, but that seems so sloppy.

  6. #6
    Forum Contributor Rhudi's Avatar
    Join Date
    03-08-2013
    Location
    South Carolina, US
    MS-Off Ver
    Professional Plus 2016 aka Office 365
    Posts
    199

    Re: Compare multi-line text cell to data in much larger text file

    I did something clunky that appears to work.
    I do a for-Loop based on the UBound of the array.
    I use Filter() to count how many times I'm looking for the match.
    When I do an Application.Match(), I just blank that array element. I won't need it any more.
    I increment my filter count and then set the loop count to my match count.
    The next loop around, the search finds the next match.
    my filter count helps it stop looking when it finds all it needs to.

+ 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] How to Compare Excel spreadsheet values with each line of text file
    By raw_geek in forum Excel General
    Replies: 4
    Last Post: 06-27-2012, 12:21 PM
  2. Replies: 2
    Last Post: 12-08-2010, 12:25 PM
  3. Multi-line text box to cell in Excel
    By Smurlos in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2009, 07:31 AM
  4. [SOLVED] multi-line text file import to excel
    By Waxaholic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2006, 03:45 PM
  5. Reading a text file line by line-How do I open the text file with VBA
    By stressman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2005, 12:29 AM

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