Find Cell Based On Last Copied Text In Word

  • I have a macro in Word that copies a string of text (a zip code). I have been manually opening an Excel workbook that contains a column of zip codes. I 'find' the zip code in the list and then tab over eight columns to copy the cell in that row containing the name of the salesman that handles that zip code. I then go back to the Word document and paste that data at the top of the document. I want to automate that part of the task.


    I have the following code:


    I just need to know to know how to get the item from the clipboard into the Cells.Find code


    Any ideas? Thanks.

  • Re: Find A Cell Based On Last Copied Text In Word


    I checked that out but still can't get it. Code now looks like:

    The "What:" value is showing up as "" when it should show the zip code I just copied from the Word doc. Not sure where I'm going wrong.

  • Re: Find A Cell Based On Last Copied Text In Word


    I don't use Word automation, so this is a shot in the dark:

    Code
    Cells. Find(What:=ZipCopy.Text ...


    Second shot:

    Code
    Dim sZip As String 
        Set sZip = Selection.Range.Text 
    
    
        ...
    
    
        Cells. Find(What:=sZip ...

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Find A Cell Based On Last Copied Text In Word


    Thanks. I get an missing object error. I'm going to try to use an input box to pop up, I'll paste the zip into that and have the code find the value of that box. Maybe that will work.

  • Re: Find A Cell Based On Last Copied Text In Word


    Wait! One more chance! Try

    Code
    Dim iZip As long
    Set iZip = CLng(Selection.Text)
     
    ... 
     
    Cells. Find(What:=iZip ...

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Find A Cell Based On Last Copied Text In Word


    Compile Error: Object Required is what I get. I tried the Input Box and it works but only if I run the macro seperately from the macro that sets up the Word doc. It's wierd. At the end of the Setup Macro I call the macro that opens the Excel workbook and does the search for the zip code and it fails to work correctly. I may just have to do this as a two-step process using two macro buttons on my toolbar.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!