
Tips.Net > ExcelTips Home > Macros > VBA Examples > 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:
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!
Have thousands of ExcelTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
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