+ Reply to Thread
Results 1 to 26 of 26

Extract unique numbers from Word and search for them in Excel

  1. #1
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Question Extract unique numbers from Word and search for them in Excel

    Hello,

    I have two documents. One worddocument with different product id:s, and a excelfile with hopefully the same numbers

    I want to build a macro that does following:

    1. Search for all numbers after the term "PRODID:" in the whole word document.
    2. See if these words can be found in the excelfile.
    3. Display the numbers who are in the worddocument but not in the exceldocument.


    I now have a short macro that can search the excel document but it requires me to manually copy all the ID-numbers from word to a excel sheet.

    I appreciate all help i can get!!

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Extract unique numbers from Word and search for them in Excel

    hi Reen, welcome to ExcelForum, can you provide Excel and Word file in question?

  3. #3
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Hello,

    Thank you!

    Here is testfiles, the entire document is over 2000 pages and is confidential so i cant share it.

    Something worth knowing is that all documents are different in design. But the ID is always on the form

    "REQID XXXXXX/" or "REQID:XXXXXX/".
    Where XXXXXX is the ID-number with 4-7 digits.

    And i dont want to extract number who isnt in that form.

    In the exceldocument the Id is just in the form "XXXXXX"

    I want to search for the words in all of the sheets in the exceldokument, and every cell.
    Tell me if im confusing you!


    Thanks!
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Extract unique numbers from Word and search for them in Excel

    please check attachment, press Run button or run code "test"
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Extract unique numbers from Word and search for them in Excel

    oops...I've noticed a mistake in the code, rectified, please check attachment
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Quote Originally Posted by watersev View Post
    oops...I've noticed a mistake in the code, rectified, please check attachment

    THANK YOU SO MUCH! This is perfect, i really appreciate it!

    Is there a way to select the excelfile in the same way as the wordfile?

    Because the IDnumber in the exelfile can be wrapped around text etc. so i really cant extract them every time.
    Last edited by Reen; 07-07-2014 at 03:02 AM.

  7. #7
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Quote Originally Posted by watersev View Post
    oops...I've noticed a mistake in the code, rectified, please check attachment
    Ive discovered one error cause of my misstake. I said that the word before the number war REQID but in fact it is REQPROD. When i changed REQID to REQPROD in the code i get "subscript out of range", do you know why?

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    This should do
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Quote Originally Posted by jindon View Post
    This should do
    Please Login or Register  to view this content.
    Thank you very much!!! Works perfect
    Is there a way to display the REQPROD that are NOT in the excel, rather than the ones who are?

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    I don't know how you want it.

    Just used msgbox.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Quote Originally Posted by jindon View Post
    I don't know how you want it.

    Just used msgbox.
    Please Login or Register  to view this content.
    My bad, i missunderstood what the program did at first!

    When i extract all REQPROD with your code, i want to compare them with the exceldocument with the following code:

    Please Login or Register  to view this content.
    And it works sometimes but most it doesnt!

    I would like to change:
    Set CompareRange = Workbooks("FileName").Worksheets("SheetName").Range("A:A")

    so that the user can insert the excelfile and search the whole document including all sheets and all cells.
    How do i do that?

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    So, you want to compare the result with the data in another workbook.
    Something like. (not tested)
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Excactly! Your code does not create any error but it doenst work. Nothing happends when i run it. Do you know what the problem may be?

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    Did you select the result range before you run the code?

  15. #15
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Yes! I added a MsgBox in the end and i can tell it runs very quick.
    In the exceldocument i want to search in the REQPROD-number isnt lined up as in te result range, the numbers can be wrapped in text etc.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    I need to see the file...

  17. #17
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Does it help if i say that the first row is a drpo-down list? and row 2 and -> is content in the list.

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    No, I need to see that data to be compared to the result....

  19. #19
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Can i give u the content of one cell? I cant share the document and its to big to change the content of the whole file..

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    All your result consists of numeric value...

    What are the data to be compared?

  21. #21
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Quote Originally Posted by jindon View Post
    All your result consists of numeric value...

    What are the data to be compared?

    For example, this is the content in ONE cell. And one cell can contain many REQPROD.

    Please Login or Register  to view this content.

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    How about
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Quote Originally Posted by jindon View Post
    How about
    Please Login or Register  to view this content.
    Works just fine i think!! Thank you so much, you have been a great help for me!

    If its not too much trouble, is it possible to select the excelfile on the same way as the wordfile. Instead of manually enter the filename in the code. Because i will use the code on different word and excel document.
    Last edited by Reen; 07-07-2014 at 09:19 AM.

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    OK
    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    07-04-2014
    Location
    UK
    MS-Off Ver
    2007
    Posts
    13

    Re: Extract unique numbers from Word and search for them in Excel

    Thank you!

    I get an subscript out of range error, debugger says this is the problem

    Please Login or Register  to view this content.

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,522

    Re: Extract unique numbers from Word and search for them in Excel

    Of course...
    Please Login or Register  to view this content.

+ 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] search for all unique numbers down a column and print a list of those numbers in another
    By JJGF in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-05-2014, 11:08 PM
  2. Search for a word in a column and extract the word
    By Abishekar in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-17-2012, 09:30 AM
  3. [SOLVED] vba to search word and extract following 3 words
    By sausis in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2012, 03:39 AM
  4. Search for and extract word from a cell
    By hmatharo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-30-2007, 10:21 PM
  5. Replies: 2
    Last Post: 05-02-2006, 11:20 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