Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2020, 04:36 PM
Guessed's Avatar
Guessed Guessed is offline Help creating a macro to identify values that have letters and numbers. Windows 10 Help creating a macro to identify values that have letters and numbers. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Hmm, it can be done but requires a more involved approach built off Graham's search method. This is my first attempt at it.


Code:
Sub HilitePartNumsHyph()
  Dim rngWord As Range, aRng As Range, sWord As String
  Dim oRng As Range, oNum As Range, rngFrag As Range
  
  Set oRng = ActiveDocument.Range
  With oRng.Find
    Do While .Execute(findText:="[0-9]{1,}", MatchWildcards:=True)
      Set oNum = oRng.Words(1)
      'oNum.Select                                  'XXXX Testing Only XXX
      sWord = UCase(Trim(oNum.Text))
      If sWord Like "*[A-Z]*" Then                  'If there is a letter included it is a part num
        Set rngFrag = oNum.Words.Last.Next
        'rngFrag.Select                             'XXXX Testing Only XXX
        If rngFrag.Text = "-" Then
          rngFrag.MoveEnd Unit:=wdWord, Count:=1
          oNum.End = rngFrag.End
          oNum.Select                               'XXXX Testing Only XXX
        End If
        oNum.HighlightColorIndex = wdYellow
        Debug.Print oNum                            'This is the output list
      End If
      oRng.Start = oNum.End
    Loop
  End With
End Sub
The behaviour is such that it will only find a compound part number (one with a hyphen) if the first fragment contains both a number and a letter
It doesn't care what comes after the hyphen, as long as Word considers it to be the 'next word'. This means it wont find N50-V12345-N51 as a SINGLE item, nor will it find 123-NNN or NNN-123. It will find N50-- and N50-8908098
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 08-10-2020, 05:11 PM
Mr J Mr J is offline Help creating a macro to identify values that have letters and numbers. Windows 10 Help creating a macro to identify values that have letters and numbers. Office 2016
Novice
Help creating a macro to identify values that have letters and numbers.
 
Join Date: Aug 2020
Location: California, US
Posts: 15
Mr J is on a distinguished road
Default

That did it! Andrew you are awesome! Graham I didn't forget about you either, I added to both the reputations on all the comments for you guys. Thanks!
Reply With Quote
Reply

Tags
numeric, phonetic, word macros



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help creating a macro to identify values that have letters and numbers. Creating your own Section Headings using Numbers and letters and linking to the TOC rehahm Word 4 10-07-2015 10:20 AM
Help creating a macro to identify values that have letters and numbers. Creating a TOC with sequential letters instead of page numbers at the right margin shansen Word 1 03-11-2014 12:43 PM
Look up cell values with mixed number and letters Cardinal2 Excel 1 02-10-2013 01:40 AM
Help creating a macro to identify values that have letters and numbers. Captions mixing letters and numbers trew Word 7 11-21-2012 12:54 AM
Help creating a macro to identify values that have letters and numbers. Creating TOC with letters and numbers tanababa Word 1 04-28-2011 01:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:49 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft