Please Help.  compare two excel files.  Can't get the find command to work

Hello, I'm new to applescript.  I'm trying to write a script to compare column B of one excel file to column B of the another excel file.
I will have to had a repeat loop to proceed down the column but I'm stuck on the find command. 
Below is some of the code I have so far.  The applescript error message is "Microsoft Excel got an error: The object you are trying to access does not exist. It highlights the find column." 
set patientFile to choose file with prompt "Please select the patient Excel file:"
set patientName to name of (info for patientFile)
tell application "Microsoft Excel"
open patientFile
set thepatientFile to workbook patientName
end tell
display dialog "Is your patient SNP data in column B of the " & " " & patientName & " " & "excel file?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
display dialog "Please put your data in column B" buttons {"Cancel"} default button 1
if the button returned of the result is "Cancel" then
end if
else
display dialog "Is column E empty? The results of this program will be stored in column E of the" & " " & patientName & " " & "excel file." buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
  display dialog "Please put your data in empty column E" buttons {"Cancel"} default button 1
  if the button returned of the result is "Cancel" then
  end if
else
  set relativeFile to choose file with prompt "Please select the relative Excel file:"
  set relativeName to name of (info for relativeFile)
  tell application "Microsoft Excel"
  open relativeFile
  set therelativeFile to workbook relativeName
  end tell
end if
end if
display dialog "Is your relative SNP data in column B of the" & " " & relativeName & " " & "excel file?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
display dialog "Please put your data in column B" buttons {"Cancel"} default button 1
if the button returned of the result is "Cancel" then
end if
else
display dialog "Does column C contain the result data you would like copied from" & " " & relativeName & " " & "excel file?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
  display dialog "Please put the data you would like copied in column C." buttons {"Cancel"} default button 1
  if the button returned of the result is "Cancel" then
  end if
else
  tell application "Microsoft Excel"
  activate object workbook patientName
  copy value of cell "A1" to cellPatientFile
  find (range "B:B" of workbook relativeName) what cellPatientFile
  if cellPatientFile is true then
  set bold of font object of cellPatientFile to true
  end if
  end tell
end if
end if
Does any one have any hints towards solving this problem?  Thank you for any help.

Hi,
taffners wrote:
Thank you everyone for your help.  I attached my code.  It works now but kinda slow.  Does anyone have any hints on making it faster.
Important : when you use the find command, it's preferable to use the properties ( look in and look at).
Example : find searchRange what searchTerm look in values look at whole
Otherwise, it will search according to the criteria of your last find.
Example, if you uncheck 'Find entire cells only', and after that you run the script,
find column 2 what 10.0 -->  match 110.0 or 1110.0 or 310.0, .... , because it look at part.
set screen updating to false : Yes it improves the speed.
Here are my tests (no duplicate values in the Excel column ) on old computer (Powermac G5) .
set screen updating to false without any activate object command
2000 rows --> 3.7 minutes,  your script : 11.5 minutes
4000 rows --> 7.5 minutes, your script : 23 minutes
8000 rows --> 15 minutes,  your script : 46 minutes
But, it's faster to search through a list without using the Excel find command, no need to set the screen updating, You can continue working on the workbook or another workbook, this will not disturb the script.
Tests on my script :
2000 rows --> 4 seconds
4000 rows --> 21 seconds
8000 rows --> 1.3 minutes
17000 rows --> 6 minutes
Here is the script :
main()
display dialog "Done"
on main()
      script o
            property patientSNP_list : {}
            property relativeSNP_list : {}
            property resultsList : {}
            property copyAnswerList : {}
            on findLookAtWhole(value) -- case sensitive
                  set {low, high} to {1, count my relativeSNP_list}
                  considering case
                        repeat while low ≠ high
                              set mid_ to (low + high) div 2
                              if value is in items low thru mid_ of my relativeSNP_list then
                                    set high to mid_
                              else
                                    set low to mid_ + 1
                              end if
                        end repeat
                  end considering
                  if (item low of my relativeSNP_list is value) then
                        set end of my resultsList to item low of my copyAnswerList
                  else
                        set end of my resultsList to {"no"}
                  end if
            end findLookAtWhole
      end script
      --opens File1.  Names it patientName
      set patientFile to choose file with prompt "Please select the patient Excel file:"
      set patientName to name of (info for patientFile)
      tell application "Microsoft Excel"
            open patientFile
            set thepatientFile to workbook patientName
            set patientSheet to sheet (name of active sheet) of thepatientFile
      end tell
      --This Dialog assigns where the data is stored for file1
      display dialog "What Column is your patient SNP data of the " & " " & patientName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
      set PatientSNPCol to (text returned of the result)
      --This Dialog assigns what row your data starts at for file1
      display dialog "What row does your patient SNP data start in the " & " " & patientName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
      set patientSNPRow to (text returned of the result)
      set patientStartCell to PatientSNPCol & patientSNPRow
      --This Dialog assigns the last row of data for file1
      display dialog "What row is the last row of you patient SNP data start of the " & " " & patientName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
      set patientLastRow to (text returned of the result)
      set patientLastCell to PatientSNPCol & patientLastRow
      --This Dialog assigns the location of the data copied from file2
      display dialog "What column would you like the results of this program stored in of the" & " " & patientName & " " & "excel file." default answer "" buttons {"submit"} default button 1
      set resultsLocation to (text returned of the result)
      --opens File2.  Names it relativeName
      set relativeFile to choose file with prompt "Please select the relative Excel file:"
      set relativeName to name of (info for relativeFile)
      tell application "Microsoft Excel"
            open relativeFile
            set therelativeFile to workbook relativeName
            set relativeSheet to sheet (name of active sheet) of therelativeFile
      end tell
      --This dialog assigns the column of data in file2
      display dialog "What Column is your relative SNP data of the " & " " & relativeName & " " & "excel file?" default answer "" buttons {"submit"} default button 1
      set relativeSNPCol to (text returned of the result)
      --This dialog assigns the column of data begining copied to excel file1.
      display dialog "What Column contains the data you would like copied to the " & " " & patientName & " " & "excel file in column" & " " & resultsLocation & " " & "?" default answer "" buttons {"submit"} default button 1
      set copyAnswer to (text returned of the result)
      tell application "Microsoft Excel" -- get values
            set o's patientSNP_list to value of range (PatientSNPCol & patientSNPRow & ":" & PatientSNPCol & patientLastRow) of patientSheet
            set lastrow to first row index of (last cell of used range of relativeSheet)
            set o's relativeSNP_list to value of range (relativeSNPCol & "1:" & relativeSNPCol & lastrow) of relativeSheet
            set o's copyAnswerList to value of range (copyAnswer & "1:" & copyAnswer & lastrow) of relativeSheet
      end tell
      set tc to (count o's relativeSNP_list)
      repeat with i from 1 to tc --convert list of lists to one list
            set item i of o's relativeSNP_list to item 1 of item i of o's relativeSNP_list
      end repeat
      set tc to (count o's patientSNP_list)
      repeat with i from 1 to tc -- AppleScript find method, not the Excel Find
            o's findLookAtWhole(item 1 of (item i of o's patientSNP_list))
      end repeat
      tell application "Microsoft Excel" -- set values
            set value of range (resultsLocation & patientSNPRow & ":" & resultsLocation & patientLastRow) of patientSheet to o's resultsList
      end tell
end main
If you have lots of rows and you want it to go faster.
I have another script that uses the power of (/usr/bin/awk and his associative arrays) in a do shell script
17000 rows --> awk : 2 seconds, applescript : 6 seconds, total : 8 seconds
34000 rows --> awk : 3 seconds, applescript : 11 seconds, total : 14 seconds

Similar Messages

  • I purchased Adobe Acrobat x Pro recently and installed it, I have compatibility issues vision 2013. The adobe pdf converter  plug in stays inactive despite all my efforts to activate it, I need help with this? How can i get the plug in to work with Visio

    I purchased Adobe Acrobat x Pro recently and installed it, I have compatibility issues vision 2013. The adobe pdf converter  plug in stays inactive despite all my efforts to activate it, I need help with this? How can i get the plug in to work with Visio 2013?

    For MS Visio (any version) only the appropriate version of Acrobat *PRO* provides PDFMaker for Visio.
    For Visio 2013 specifically you must have Acrobat XI Pro (updated to at least 11.0.1).
    See: 
    http://helpx.adobe.com/acrobat/kb/compatible-web-browsers-pdfmaker-applications.html  
    Be well...

  • Can't get the "find" function to work in Bridge CS4?

    Hello there,
    I need a bit of help with the Find funtion in Brdige CS4. Basically it doesn't work. I've got a folder with multiple files and keywords and the search brings up "no results" regardless what I do. What could be the problem?? I'm running Windows XP.
    thanks,
    Geordie

    In the Masked Artwork folder go to a photo with the keyword "food".   Does it have a check mark at food?
    I have had situations where the photo had the keyword printed under the title, but the check mark is not present.  A search with that combination for the keyword yields "no image found".
    Go to bottom of your keywords panel and look under Other Keywords.  Is Food there and checked?  If so you can right click on this keyword and Find will work.  If you have the type of situration where keyword has no check mark in your tree, except for at Other, I found you have to delete them and then re-enter them.  It will then work.
    Let me know what you find discover.

  • I purchased Adobe Acrobat x Pro recently and installed it, I have compatibility issues vision 2013. The adobe pdf converter  plug in stays inactive despite all my efforts to activate it, I need help with this? How can i get the plug in

    I purchased Adobe Acrobat x Pro recently and installed it, I have compatibility issues vision 2013. The adobe pdf converter  plug in stays inactive despite all my efforts to activate it, I need help with this? How can i get the plug in to work with Visio 2013?

    For MS Visio (any version) only the appropriate version of Acrobat *PRO* provides PDFMaker for Visio.
    For Visio 2013 specifically you must have Acrobat XI Pro (updated to at least 11.0.1).
    See: 
    http://helpx.adobe.com/acrobat/kb/compatible-web-browsers-pdfmaker-applications.html  
    Be well...

  • How can i compare two excel files with different no. of records.

    Hi
    I am on to a small project that involves us to compare two excel files. i am able to do it but am struck up at a point. When i compare 2 different .csv files with different no. of lines i am only able to compare upto a point till when the number of lines is same in both the files.
    Eg. if source file has 8 lines and target file has 12 lines. The difference is displayed only till 8 lines and the remaining 4 lines in source lines are not shown.
    Can you help me in displaying those extra 4 lines in source file. I am attaching my code snippet below..
    while (((strLine = br.readLine()) != null) && ((strLine1 = br1.readLine())) != null)
                     String delims = "[;,\t,,,|]";
                    String[] tokens = strLine.split(delims);
                    String[] tokens1 = strLine1.split(delims);
                   if (tokens.length > tokens1.length)
                    for (int i = 0; i < tokens.length; i++) {
                        try {
                            if (!tokens.equals(tokens1[i])) {
    System.out.println(tokens[i] + "<----->" + tokens1[i]);
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + tokens1[i]);
    out.println();
    sno++;
    } catch (Exception exception)
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + "");
    out.println();
    Thanks & Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    A CSV file is not an Excel file.
    But apart from that your logic makes no sense.
    If the 2 files are of different sizes the files are different by definition, so further comparison isn't needed, you're done.
    If you want to compare individual records, you need to compare all records from one file with all records from the other, unless the order of records is important in which case your current system might work.
    That system however is overly complicated for comparing CSV files.
    As you assume a single record per line, and if one can assume those records to have identical layout (so no leading or trailing whitespace in or between columns in one file that's not in the other) comparing records is simply a matter of comparing the entire lines.

  • How to compare two excel files in java ?

    how do i compare two excel files in java.?
    I have two excel files stored on my computer in d: drive.
    Ex:
    D:\\file a
    D:\\file b
    How to compare the contents of these two files and print " files are equal " or "files not equal "

    Javamastermahe wrote:
    I mean i want to print on the console "files are equal " or any message like " both the files match "If this is your requirement, this program satisfies it...
    import java.util.Random;
    public class SuperExcelTester {
        public static void main(String[] args) {
            Random rnd = new Random();
            String[] messages = {
                "files are equal",
                "files are not equal",
                "unexpected error"
            int index = rnd.nextInt(messages.length);
            System.out.println(messages[index]);
    }

  • My InDesign document has two page 1s and I can't get the page numbers to work.  Help!

    My InDesign document has two page 1s and I can't get the page numbers to work.  Help!  How do I fix this?

    Do you mean the first section is starting at page one?
    And the second one now is starting at page two?
    So I would ask why you would need sections at all?
    Did you set the controls for Automatic Page Numbering?
    If you select the particular page where section two is starting in the Pages Panel, you could untick the Start Section option in the numbering and section dialog. That would remove the section. You cannot do that with the very first section, but you should set the first section to Automatic Page Numbering if you ever want to use your document with an inDesign book file.
    Uwe

  • Hello, so today I realized that my iPhone with iOS 6 is frozen on the music. I can get back to the home screen but I can't get the music player to work because its frozen on the w's and will not respond to touch. I would be grateful for any help on this.

    Hello, so today I realized that my iPhone with iOS 6 is frozen on the music. I can get back to the home screen but I can't get the music player to work because its frozen on the w's and will not respond to touch. I would be grateful for any help on this.

    Hi deamayfield,
    Thanks for visiting Apple Support Communities.
    If your Music app is unresponsive, try restarting/resetting your iPhone:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    Best,
    Jeremy

  • After I exported a PDF to a Word doc and downloaded it, I can't get the pointer tool to work.

    After I exported a PDF to a Word doc and downloaded it, I can't get the pointer tool to work. When I click on the document text, the only tool is the "move" tool. I can't edit or select text. Please advise.

    Version of Adobe: Adobe ExportPDF (not Pro)
    Operating system:  Windows 8.1
    Steps I am taking: When the PDF file is selected and opened, I clicked on Tools menu on right side of the screen; then I clicked on Select PDF file; then under Convert To, I selected Microsoft Word (*.docx); then I hit the box below that; and clicked Convert. I then see the message that says it is Converting to Export PDF Online. Then I see a link below that, that says Download Converted File. This takes me online to Adobe Acrobat .com, where, I see the command, Export PDF, and see a blue box on the same screen that says Select PDF Files to Export. I click on the thumbnail of the file I want to export. This brings up, online, a screen containing the file I wanted to convert to Word. Then, on the same screen, I click on the icon on the right hand of the screen that says Download. then I click on the box on the bottom the screen that contains the Word document I had wanted to convert. This brings up the Word doc. in Compatibility Mode the latest Word version, which I am unfamiliar with and which has a Picture Tools tab that I cannot escape from and I cannot get any selection tool other that the Move pointer, and I cannot find the Select text pointer to select any text on the page. I don't want this Word version and do not know how to return to the old version of Word that I am familiar with.
    Can you help me, please?
    Theresa Julia Schuer

  • Can not get the WebCam NX to work on yahoo messenger!

    Yes I can not get the webcam nx to work on yahoo messenger. I can send video and snaphots but I can not get it to work on yahoo messanger. What am I doing wrong? What do I need to do to get it to work. I just wanted it for the use of a web cam on yahoo messenger. What do I need to do. Please help! I have windows XP SP2 and yahoo messenger 6.0. So what do I need to do?
    Ashley

    Try going to this web site it worked for me. Evidently Yahoo knows about the problems with the web cams.
    http://help.yahoo.com/help/us/messen.../webcam-5.html

  • I can't get the mp3 player to work

    I can't get the mp3 player to work after I paid for it

    I keep getting a triangle with and exclamation mark no matter what I rename my mp3 file to. I put the mp3 file into my muse folder desktop, any hints?

  • Answer: to How can I get the reset button to work.

    How can I get the reset button to work?: Answer
    Thanks to everyone who helped on this. You are awesome. Especially Ned!!  Posted here because I was unable to add more to the existing post.
    Here is the question:
    When you click on the reset button, this error below comes up. If you can't find the button it is the navy colored rectangular thing in the lower left corner of page.
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
        at flash.display::DisplayObjectContainer/removeChild()
        at AddATree2/onReset()
    When you click on the reset button, this error below comes up. If you can't find the button it is the navy colored rectangular thing in the lower left corner of page.
      Here is the answer:
    //when you click the reset button everything is removed from the stage
        //except the star, baclground, and reset button (trees and greeting REMOVED)
        public function onClear(Event:MouseEvent):void
                if (tree3) removeChild(tree3);
                if (tree2) removeChild(tree2);
                if (webText) removeChild(webText);
                if (tree) removeChild(tree);
                clickCount = 0;

    This is the answer to what to put in the onclear function.

  • How can I get the right click to work in firefox -- it works in internet explorer

    how can I get the right click to work in firefox -- it works in interne

    Try the Firefox SafeMode to see how it works there. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    * You can open the Firefox 4/5/6/7 SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    * Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    If it is good in the Firefox SafeMode, your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes

  • How can I get the readability bookmarklet to work

    Firefox 3.6.8 in Windows XP Home on a Toshiba netbook. How can I get the "readability" bookmarklet to work? It works just fine in Camino on an Apple mini desktop computer running OS X 10.4.11 (Tiger.) Readability uses javascript, which I do have turned on. The problem (of it not working) doesn't seem to have anything to do with the NoScript add-on either, as I tried allowing everything on the page and it still didn't work. Any ideas of what to try next?
    ''Duplicate post, continue [https://support.mozilla.com/en-US/questions/746624 here]''

    Hi there.
    By chance, I too have the readability bookmarklet installed (but I don't use it that much, to be honest), and it works ok for me. It's possible that you are having a problem with some Firefox add-on that is hindering your Firefox's normal behavior. Have you tried disabling all add-ons (just to check), to see if Firefox goes back to normal?
    Whenever you have a problem with Firefox, whatever it is, you should make sure it's not caused by one (or more than one) of your installed add-ons, be it an extension, a theme or a plugin. To do that easily and cleanly, run Firefox in [http://support.mozilla.com/en-US/kb/Safe+Mode safe mode] (don't forget to select ''Disable all add-ons'' when you start safe mode). If the problem disappears, you know it's from an add-on. Disable them all in normal mode, and enable them one at a time until you find the source of the problem. See [http://support.mozilla.com/en-US/kb/Troubleshooting+extensions+and+themes this article] for information about troubleshooting extensions and themes and [https://support.mozilla.com/en-US/kb/Troubleshooting+plugins this one] for plugins.
    If you need support for one of your add-ons, you'll have to contact its author.
    If the problem does not disappear when all add-ons are disabled, please tell me, so we can work from there. Please have no fear of following my instructions to the line, as all can be easily undone.

  • I can't get the finger service to work in Messaging Server 3.01.

    I can't get the finger service to work in Messaging Server 3.01.
    <P>
    This is a known problem in 3.01. There is a patch which
    fixes this problem. It is available at:
    <P>
    ftp://[email protected]/messaging/m301ptch.exe
    <P>
    the password is: bet@NOW!

    Hi David
    Say you have term <foo> and definition <bar> pair. Here term (any text you want highlight) is used in document at many places and definition is defined once as complete paragraph anywhere (i.e. in table cell). if same term is define at multiple places first definition is taken.
    Use marker text same as your term text <foo> for tagging both term and definition.
    Use Glossary marker to tag definition
    Use GlossaryTerm marker to tag term
    We have taken feedback to update the FrameMaker help on this.
    For in place highlighting you may also try expanded text  http://help.adobe.com/en_US/FrameMaker/9.0/Using/WS9FDAD957-2A30-4251-B520-EC32E0A8097B.ht mlhttp://help.adobe.com/en_US/FrameMaker/9.0/Using/WS9FDAD957-2A30-4251-B520-EC32E0A8097B.ht ml   Now in FM 12 expanded text  is inside Special > Publish Options > …
    Hope it clarifies your doubts
    Thanks
    Amit 

Maybe you are looking for