bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Macros > VBA Examples > Extracting Proper Words

Extracting Proper Words

Summary: If you’ve got a list of potential words, and you want to know which of those potential words are real, you’ll appreciate the techniques described in this tip. You can either manually perform the analysis, or use the handy macro provided. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

Vanita has a worksheet that contains different combinations of letters in each cell of column A. He is looking for a way to extract the words from that list that are "proper," meaning that they are found in a spell-check dictionary.

Assuming that the column contains only words (no spaces, punctuation, or phrases), you can manually check the list in this manner:

  1. Make a copy of column A into column B. You now have two identical columns.
  2. Select column B and run spell check.
  3. Every time a spelling change is suggested, accept it. When done, you should have column A as your original and column B as a spell-checked version of column A.
  4. In column C, enter the formula =IF(A1=B1,B1,"") and copy the formula down. This formula only shows a word in column C if the original word matches the spell-checked version of the word.
  5. Copy all the words in column C and use Paste Special to paste Values into another location. You now have a list of validly spelled words.

If you need to perform the validation process regularly, you may want to use a macro to instead create your final list. The following macro steps through the word list in column A and clears any cells that contain words not in the dictionary. After checking all the words, it then deletes all the cleared cells.

Sub ExtractDictionaryWords()
    Dim rWords As Range
    Dim rCell As Range

    Application.ScreenUpdating = False
    Set rWords = Range(Range("A1"), _
      Range("A65536").End(xlUp))
    For Each rCell In rWords
        If Not Application.CheckSpelling(rCell.Value) Then
            rCell.Clear
        End If
    Next
    On Error Resume Next
    rWords.SpecialCells(xlCellTypeBlanks). _
      Delete (xlShiftUp)
    On Error GoTo 0
    Set rCell = Nothing
    Set rWords = Nothing
    Application.ScreenUpdating = True
End Sub

Remember—this macro is intentionally destructive in its behavior, meaning that it clears out cells. If you have any need for the original data, you'll want to run the macro on a copy of the data, not on your only copy.

Tip #2834 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007


Save Time! ExcelTips has been published weekly since late 1998. Past issues of ExcelTips are available in convenient ExcelTips archives. Have your own enhanced archive of ExcelTips at your fingertips, available to use at any time!
 
Check out ExcelTips Archives today!

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)