Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    44
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Finding Numbers (VBA/Word 2000)

    Hello all! I hope somebody can help me! I've stared at code all day and cannot figure this out!
    I created a macro several years ago that searches through a document to find numbers - once a number is found, it backs up X number of words [designated by user] and copies/pastes that text (along with page, column & line number) into a table just created in a new doc.

    Yesterday, somebody noticed that the macro only captured the first single digit number - after that it only captured 2 digit numbers [it's supposed to find up to 4 digit numbers]. The macro ran the search, did its copy & paste, then entered a do loop. The first search result went through a select case statement including "case > 0..." but everything inside the do loop only had "case > 10." Easy, right? Change the case option inside the do loop to 0 like the one outside the loop. Well, no..
    That single change now finds the first number and subsequently logs every single character after it - be it a number, a letter, punctuation - WHATEVER!

    I'm not a programmer by title - but I enjoy working with code and would love to figure this out. After two days of it, though, I'm at my wits end. I've tried everything I can think of... and pretty much everything I've found online. In the macro's current state, I have it moving to the end of doc, inserting a 999 & running then running the search - (1-9){1,4} - and recording everything into that new doc with a table. Inside the do loop, I added a "if the lastpage variable = currentpage variable & if the lastline variable = currentline variable" statement AND case = 999 check. My problem is... it skips over the entire last page. Thus, my 999 is never found and the check is a waste. I contemplated checking the character count and measuring against that... but if my last page gets ignored - a fat lotta good it will do me! [also tried 99 & 9] I haven't even GOTTEN to the whole "ha, ha I'm ignoring 3 and 4 digit numbers" issue!

    I will try to attach the code as it exists now [please excuse all the commented lines - I'd try something, then end up coming back to it...so I didn't delete] and an "altered" sample doc. Sorry - can't send the full text.

    Any and all suggestions would be appreciated.
    My thanks in advance -
    MMMorrow
    Attached Files Attached Files

  2. The Following User Says Thank You to MMMorrow For This Useful Post:

    Shoru (2011-12-21)

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Finding Numbers (VBA/Word 2000)

    You insert a space before the search text, but you don't insert a space before the 9 at the end of the document, so this 9 will not be found by the code.

    It's not very clear to me what you expect. I have attached a zip file with a slightly modified version of the macro and the result it produces from your sample document. Can you indicate where it is "wrong"?
    Attached Files Attached Files

  4. The Following User Says Thank You to HansV For This Useful Post:

    Shoru (2011-12-21)

  5. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Harrisburg, Pennsylvania, USA
    Posts
    44
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Re: Finding Numbers (VBA/Word 2000)

    Hans -
    Many thanks! I needed to tweak your attachment just a bit - but it's working beautifully! I'd been staring so long that I totally missed adding the space before the search text!
    Your code is not "WRONG" at all!! It produces what we expect: a list of numbers & their document locations with reference text.

    BLESS you for your help - I really appreciate it! THANK YOU!!
    MMMorrow

  6. The Following User Says Thank You to MMMorrow For This Useful Post:

    Shoru (2011-12-21)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •